If you are dealing with 2D graphics, you must have dealt with polygons. Polygons such as:
Polygons under a are called convex polygons and those under b are called concave. There is also another kind of classification: simple and complex polygons. All of the above polygons are simple. If you draw a following polygon using 5 straight lines, then it is a complex polygon.
The same shape can also be drawn with more lines. In that case, this shape can represent three triangles, that is, three separate polygons that are merely positioned together.
If you wish to calculate intersection of two polygons, this can be relatively simple for convex polygons but a little bit trickier for concave and especially for complex polygons.
Convex polygon intersections:
Concave polygon intersection:
I created a javascript library that take 2 polygons and return a third polygon that represents an intersection of the given 2 polygons. It works for both convex and concave polygon, but probably not as expected for complex polygons. Polygons are javascript arrays of Points. 'Point' is any javascript object that has both x and y numeric properties. The order of points in an array that defines a polygon is very important. The same set of n points can produce n! different polygons. Most all of them will be complex.
Za mene je društvo čovjeku isto što i šuma stablu. Šuma nema neku vrhovnu ideju što bi trebala biti i kako bi trebala izgledati. Ako se dogodi devijacija na jednom od stabala, u istom trenutku ta devijacija ulazi u definiciju šume, i prestaje biti devijacija. Neće nitko probirati u šumi samo ravna vertikalna stabla i reći: "Ova stabla sačinjavaju šumu. Ostala su samo nametnici." Ideja o tome što šuma jest, prilagođava se svakom pojedinom stablu.
Tako da mi apsolutno nema smisla kako se ponekad govori o odnosu čovjeka i društva. Društvo u mojoj okolini je sve ono i samo ono što ja odredim. Ako odredim da ću od sutra hodati isključivo na rukama, onda od sutra i društvo radi minimalni pomak u tom smjeru. Pa ja jesam društvo isto kao što kap vode jest more.
A very interesting contraption. Driven by the force of gravity the ball’s movement is forming an interesting trajectory. Consecutive runs show that, however interesting this trajectory may be, it will be exactly the same every time we run it. This device can therefore be considered as a deterministic machine. Every time we produce the same input (the ball), it produces the same output (movement of that ball across a predefined trajectory).
Let’s look at something a bit more common.
Anyone who has ever played this game must have witnessed a situation where 10 some balls are simultaneously moving, bouncing of each other and falling into holes. During this brief moment (until the balls settle down) you can sense a childlike feeling of exhilaration and anticipation because your surroundings are set in motion in such a way that the outcome cannot be predicted. Observing exclusively one of the balls and disregarding everything else gives us no choice but to acknowledge that the ball is moving in a nondeterministic way. Taking, however, the whole table into consideration, it is obvious that it's not the case.
Seeing these two examples being put in the same basket of deterministic systems, a person can say: “Well, in that case everything we observe is deterministic, since everything that happens was triggered by a cause and will become a part of the cause for the upcoming events.”
This attitude is so deeply sown into the fabric of modern science that it has become a standard practice that every observed nondeterministic behavior is automatically accredited to inadequate modeling of natural laws as they are probably not taking all the factors into account. And rightly so. After all, this approach has brought more good to mankind than most of the philosophical ramblings of which some you will find in the following text.
Humans allegedly possess what is commonly referred to as self-consciousness. I tried to define that term as thoughts that lead to behavior that does not match a simple stimulus->reaction model. Stimulus, in this case, would be everything we perceive now and have perceived in our lifetime.
Human race went through various stages in history. Each of these stages was accompanied by self-conscious thoughts about the nature of the world. In these thoughts there was often a rooted idea that the world has two aspects. These aspects were considered to have so little in common that they were often referred to as two worlds: spiritual and material. This was pretty much a constant thing in human history. Only the contents of these two worlds were never finally agreed upon. For example, in prehistory, the material world would include a wooden tool, a rock in a field, a leaf in a pawn… while birds, stars, snakes and moon would all be considered spiritual. Over time, most of the stuff from the spiritual world “migrated” to the material world. These migrations lead me to believe that things and events that are considered unpredictable (nondeterministic) are often associated with the spiritual world. A story about “Once upon a time everyone thought the Earth was flat…” would fit nicely here, but why go that way? There is immeasurable eagerness in revealing all the tricks the universe has cleverly designed to disguise its true nature, but zero in revealing even one disguise in our everyday lives.
Majority of people regard themselves as spiritual because of their self-consciousness, free will and the inherent nondeterminism. If a man were to behave strictly according to stimulus->reaction model that would allude that his behavior is deterministic, therefore he has no free will and his self-consciousness (if he had any) is not of much use.
With development of neurosciences, we acquired some insights about the man’s driving mechanism – the brain. Sensational news saying that scientists discovered regions in the brain controlling motor skills, balance, long term planning, stress management and even the parts that are active during contemplation and meditation. Things started to be a little less abstract so the new protagonists became neurons, nervous system, electric charge inside human body carrying information.
So, I guess a simple version of how-does-human-body-work would be the following. A certain neuron that is designated for arm muscles transmits an electric impulse through nerve pathway to the arm and informs it what to do. Then, of course, we traverse back and ask “Who triggered that muscle neuron into doing what he did?” After that, we find out there is a hierarchy inside a brain, so a “superior” brain region ordered muscle neuron to do its thing. If we continue down this path, we will probably find out that the main perpetrator for arm movement is most certainly something perceived from person’s immediate surroundings combined with long term (probably subconscious) memory. Both of which were stated in the definition of stimulus in the stimulus->reaction behavioral model.
Still feeling spiritual?
“This is all nonsense”, you might say. “I have a free will. I decide whether to turn left or right. I control whether to blink once or twice. I am not a robot with hard drive, RAM, CPU and I/O devices.”
To cut the long story short, there is no way to prove that something is deterministic or nondeterministic. Regarding spiritualism, it might ironically turn out that the word “I” you use extensively to reclaim your spirituality is the one thing that’s keeping you away from it.
If a human being is a deterministic system, wouldn’t it be safe to assume that the entire universe is also a deterministic system?
This would imply that if someone knew the exact current state of the universe, he/she would know the exact state of the universe in any given point in time. This first person to formulate this idea was Pierre-Simon Laplace so this hypothetical all-knowing creature was later given a name – Laplace’s demon.
Quantum physics deals with the smallest known building blocks of the universe - quarks. Oddly enough, nondeterminism turned out to be not only accepted but an integral part of this science. Werner Heisenberg was the one who has proven that it is physically impossible to determine both exact position and speed of a quark. This is known as the Heisenberg’s uncertainty principle and as Steven Hawking put it: “It is a fundamental, inescapable property of the world”. Since these particles are the fiber from which everything is built, uncertainty principle is, in a way, applicable to the entire universe.
There is no agreement in the scientific community as to what is really going on in the microscopic world of quantum mechanics. There is agreement with the results of quantum experiments and observations. The problem comes when those results are interpreted. (Herbet, 1985.)
Quantum physics went on and discovered that not only is the world fundamentally nondeterministic, but also that the observation of quantum-scaled experiments affects the results of those same experiments.
My study of quantum physics made me realize that it is a psychological science as well as a physical one. This realization followed from the fact that the observer had a dramatic effect, as a result of choosing what to look for, on the results of his observations. (Wolf, 1984.)
The
world of quantum physics in a large part still remains a mystery. One
thing we can be sure of is that on a certain level our world is interconnected in such a way that we cannot anymore perceive reality as a set of separate objects interacting in accordance with a bunch of strictly predefined laws. Quantum physics reintroduces
nondeterminism in human understanding of nature, at least for time
being. Curious thing is that this nondeterminism takes place on a
tiny scale and seems to have a very limited (if any) effect on a
“normal” scale events and objects. Nevertheless,
if humans wish to pursue their identity of self-conscious, spiritual
beings, this is where they should look for clues. If they possess any
nondeterminism in them, this is where it’s coming from. How would
that be possible? As we said, quantum effects are limited to the
atomic scale and we as humans are operating on a scale where quantum
random glitches have no influence.
Well,
I guess what we would need is sort of an amplifier that can transform
a tiny quirk into an avalanche of consequential events. Something
like this.
A tiny
push in the beginning managed to produce a drastic outcome. It
wouldn’t have been possible if the entire machinery hadn’t been
set up the way it was. Each of the machine's parts is very unstable and
sensitive to any kind of stimulation.
As you
might have assumed, we already possess such a device. It is the human
brain. Or any brain for that matter, only the human brain is the most
sensitive of all we have encountered. It operates by transmitting
information using electric charges and its neurons therefore must be
pretty sensitive to the random glitches occurring on the electron
level.
Like
science has taught us so many times before: “If it’s
nondeterministic, we are not looking at the whole picture.” We can
abstract the quantum level nondeterminism as the influence of another dimension(s) that are not a part of our space-time continuum on the ones that are observable to us. If we wanted to be
poetic, we could say that these “random” glitches are in fact
messages from that other dimension. It is clear that these messages are
happening everywhere across the universe, only we (life forms,
especially humans) are capable of amplifying their effect on the
observable dimensions. Like the complex machine from the video above
amplified a slight push of a metallic wheel into something much more
noticeable.
Like I
mentioned before, the word “I” might become a stumble stone in
your quest for spirituality. It is difficult to assign a meaning to
that word if you start seeing yourself as a “mere” amplifier.
Quotation marks on “mere” imply that everyone should still
prefer to be a amplifier instead of a guy banging on his chest quite
deterministically: “I am a master of my own destiny!”
The
shift in the perspective causes you to see that the life is living
through you and not that you are living a life. Death no longer seems
to be a big deal. If life is not mine, then I cannot lose it. Life
will always be the same across the universe and in some way I will
always be a part of it.
Looking
at other people as "portals" to other dimensions also changes both your
attitude towards strangers and your current relationships. Suddenly you feel privileged to sit in the
bus next to another person instead in the empty section. Even if the person is an ugly, fat, sweaty, homeless guy. Because you know that he is essentially same as you, a self-conscious
stream of unobservable life into our observable universe.
It has been more than two months since I wrote my last report. Life started rolling on in it's normal way. Only while writing this blog I regain the feeling that nothing is actually normal. Everything is refreshingly different from home, but it was due time for me to get used to it.
I still live alone in two-bed room, but I was told that one student is coming in June to the residence and that they will put him with me in the room.
One piece of information: the protocol for downloading torrents is blocked from university network. I tried a lot of workaround, and managed to get some download but it was very rare and the speed was awful.
Life is Porto is very relaxed. People here are immune to stress. Whether it is a positive or a negative one, they don't tolerate it. Everything can wait. That is most evident in Portuguese administration. I have three friends already complaining how Portuguese administration managed to make their lives very complicated. Two friends waited for several months for their grants to be paid in full. This could all be some coincidence if I didn't personally know a girl who is also on exchange and works in the International Office at the Rectorate of University of Porto. She explained to me in details how student e-mails stay unread for several days and unanswered for several weeks without any cause other than the people there don't feel like working.
FC Porto
(recapture your love for football)
Porto's finest football team enjoys a great fame and united support of all its citizens. And rightfully so, considering that despite Benfica (Lisbon) having better predispositions for football success (bigger city, better financial background), Porto still year after year demonstrates domination not only in Portugal but also in European championships. I've actually met Slovakian students on Erasmus that have been living here for an entire year. They started visiting Porto home matches within months after they moved here and they were really passionate about it.
Futsal is also very popular in Porto. For me it is actually one of rare occasions to speak and interact with Portuguese people over longer period of time. Neighbourhood's futsal playground is the place where I learnt most of the Portuguese language I speak.
In May, there is a traditional celebration called Queima das Fitas which lasts one week. All students walk around the town yelling and wearing black harry potter outfits with funny cylinder hats and sticks in various colours. They are often kicking each other on the head with a stick, so probably the purpose the hats is also to protect the head. Only the senior students who are finishing college get hit on the head because it is actually something like a knighting ceremony here. Only difference is that here everyone is drunk. In Matosinhos there is a big area surrounded by fences, where concerts are being held all week. Inside that area, every faculty has its own stand where they sell alcohol. Every stand has its own theme and its own music. Each year, a lot of even internationally famous singers, DJs and music groups make an appearence on this annual Portuguese festival.
Sea is very cold. Temperature of the sea can go up to 18°C. Higher than that maybe in extremely rare occasions. Surfing is very popular in Porto. For Erasmus students there is a special discount on surfing courses and a lot of students use it. I went surfing only once and it was great. I always forget to go to ESN office to apply for some more surfing classes.
Another great thing about Porto is that it's very well connected to other European cities via low-cost flights. RyanAir, Transavia, and probably many other companies travel to Porto. It is normal to find a return flight to Barcelona, Madrid, Paris for no more than 30€.
Food here is slightly different than what I was used to. Portuguese people eat a lot of fish especially Bachalau. They have a lot of different recipes for this fish and it is considered traditional food here. Other characterstic dish is Francesinha. I tried it in couple of places and the taste was very different, so if you don't like it the first time, you should try some other place, every restaurant has different recipe. Near the river, there is one restaurant called "Verso em Pedra" which has a special "Mega Francesinha" in the offer. This is sort of a competition, because whoever successfully eats a mega francesinha alone within one hour, recieves a prize: an electric guitar. I forgot the brand of the guitar but I know it is very high quality. It should be, because nobody has ever won the prize. I would say it's close to impossible because I actually saw that meal. They say it's 3kg, but i think it's even more. The price of mega francesinha is 35€ so it could be a good idea to order it regardless of the competition for 7 or more people to eat. A normal meal to order if you are hungry and don't want to experiment much is "prego em prato". That's a steak with egg and potatoes. Pastel de nata is my desert of choice. It's so creamy and delicious and you can buy it almost anywhere, including in supermarkets.
I was using the camera for several months with no problems when suddenly after a few weeks of inactivity I tried to use it and I couldn't take pictures anymore - the camera reports "memory full".
I took out the memory card, plugged it into my laptop and deleted all pictures and videos, put it back into the camera and still the same message appeared even though there is no picture nor videos on the memory card.
FIXED:
All I did:
1) extract the memory card
2) put the camera on charging (to recharge the battery)
-> try to take pictures while the camera is charging without memory card, this should work
3) when it's fully charged, put the memory card back in and everything should be ok
Say you need to make record of users' activity. Each time you check upon a user and see that he was active since you last checked him, you add 1 point to his activity.
Example:
Current time is: 2012-03-26 20:42:38
We use some other service (not important which one) to find out whether user was active since we last checked him or not.
For simplicity, we assume that all users had some activity since the last time they were checked.
I check upon user#1.
I need to distribute 1 point of activity across the times of day.
Since it was the same evening since we last updated this user, we add 1 point to 'evening activity'.
Then i check upon user#2.
Since his last update 12.95 hours passed. 2.25 hours of that time was in the morning, 6 hours were during the day and 4.7 hours was during the evening. In the same ratio, 1 point should be distributed to the day parts (morning, day, evening). This means: 0.174 to 'morning', 0.463 to 'day' and 0.363 to 'evening'.
In the case of user#4 we would like to do something like this:
Since last update of this user 57,133 hours passed. We create variable hour_inc = 1/57.133.
Then we add (hour_inc*8) to 'night', (hour_inc*5) to 'morning', (hour_inc*6) to 'day' and (hour_inc*5) to 'evening'.
Sumation of these increments in this case is less than 1.
So if we want to do this for arbitrary 100 users from this table and we want to update existing information based on the information we just calculated, how would we do it?
Is it possible to do it with one with one SQL statement?
I don't think so... if you know let me know...
So the first thing we do. We open our programming language of choice and make a function that will do this for us:
{
1) do a SELECT query to fetch needed data
2) iterate through users and calculate new activities for each one
3) after that, we do a 100 of consecutive update statements. Each update statement is different because 'last_update' time for each user is different
}
The other approach is using stored procedures.
We make a procedure that uses a cursor and iterates through all users.
For each of them builds up a big UPDATE statement (string) using concatenation in combination with some form of loop.
After a statement is built, we use PREPARE-EXECUTE to preform a statement which was up to now in a some variable of type VARCHAR(1500).
The thing that I observed is that using this approach 20000 users gets correctly updated in up to 7 seconds.
Then I modified the stored procedure so that it doesn't apply those update statements but instead prints them out using SELECT command.
I copied one of update statements, made a complement update statement that annuls first one's effect.
Then I copied this pair many times until I had 500 update queries. I executed them and waited 34 seconds before it finished.
That is the duration of merely updating information in database, not including the time it took to calculate this data that is being put in database. While the stored procedure does the calculation + update within 7 seconds for 20000 users.
If I did everything right, THAT is pretty impressive.
It's been 3 weeks since I arrived to Porto. I'm a student of computer science from Croatia, now studying at Faculdade de Engenharia da Universidade do Porto - FEUP.
I got here by myself so I basically didn't know anyone the first few days. In some way I feel like I still don't know anyone, but I guess that depends on how do you define "knowing someone".
So, what are the experiences so far...
Portuguese girls in average are not as nearly as pretty as Croatian girls.
They put kitchen tiles on the outside of their houses in the old city core.
There is a tradition in Portugal that the students wear funny looking "Harry Potter" outfits (black suit with some kind of cape).
It is not obligatory, but they respect this tradition very much.
They group in some way, and leaders of those groups also carry around some sort of wooden spoon that I first thought was a rowing paddle. They wear it all the time when they are outside, regardless of the weather. It amazes me to see how many of them are doing it. It's like carnival whole year long.
Not everybody can wear it, though... First year students need to pass the initiation period during which they are compelled to do all sorts of humiliating activities. This lasts from the start of academic year until May.
In May there is a holiday with huge ceremony in the streets of Porto where all freshmen can finally wear these black uniforms.
In a way I can understand it because there is a lot of young student that come here from many parts of Portugal to an unknown environment to study. For them it's a way to bond to other students who are in similar situation.
Still, I could never picture myself wearing that.
A majority of people don't speak English. I guess that is the case in all nations that speak one of the biggest languages in the world - Chinese, Spanish, Portuguese, French, German, Italian, ...
People are often late for appointments. And I don't mean 5-10 minutes late. 30 minutes to 1 hour and 30 minutes... that's the range. Or many times they just don't show up. This is not just my observation, I heard it from a lot of people.
The Erasmus students here are 50% Brazilians... Prior to my arrival, I heard all these stories about Brazilian hedonistic life-style and general laziness. But I have had contact with only one Brazilian with those characteristics and only over e-mail.
In my experience, foreign students come here to party. It's high school all over again for them. Party all the time, drinking also... I don't mind that. I like beer, sangria, martini... But the way they drink, it's not for humans.
Before I came here, my expectations were not high. I thought I will make some Portuguese friends, go surfing, play futsal in the afternoon, learn some basics of Portuguese language... basically integrate myself in a domestic culture.
These goals now seems hardly achievable. People here have their own lives, friends, daily routines, families... it's difficult to get involved in all of that.
On the other hand, the Erasmus students are more often willing to connect with new people. So that makes foreigners form their own groups instead of mixing with the locals.
I live in student residence Alberto Amaral. It's cheap (130€), I have two-bed room all for myself. But at any time that could change. I don't have kitchen, but student canteen is a hundred meters from the dorm. I have my own fridge. There is a microwave in the lobby, also a big fridge and TV with like a hundred channels. I don't it watch very often, only English Premier League on weekends and Champions League during some weeks.
One thing to take into consideration if you are on exchange in Porto during winter or early spring: ordinary flats here don't have any kind heating installed. Rooms in a dorm do.
Laundry is done in a special room here in a dorm. You need your own detergent, softener and whatever... Washing machine works on special coins. One coin costs €2. There is also a dryer (usage is free, no coins), and the ironing board.
Student canteen, price of lunch or dinner is €2.30, but it's not even worth the money. You always have 4 menus at your choice: Vegetarian, Meat, Diet, Fish. I only haven't tried Diet. Of other three, Vegetarian seems to be the best choice every time. The meat in the canteen is simply awful.
Transportation.
The city is divided in zones. When you buy a monthly ticket, you have to choose which zones you want to include. Price of monthly ticket depends on number of zones you use. I use two zones and pay monthly ticket €22.5.
For now my estimation of monthly expenses are like this:
€130 - accommodation
€30 - transportation
€280 - food
€7.5 - phone
Those are some kind of fixed monthly costs. There are also one-time purchases (glasses, spoons, knives, cleaning detergent, sponges, iron...) and variable monthly costs. Variable monthly costs (drinking, chocolate, ordering a pizza, ...) you can always cut down if you need to save up money.