Thursday, December 20, 2007

Week 9 (17 Dec - 21 Dec)

Monday, 10 December 2007
Week 9 has come (and gone, for when I'm typing this entry, its Friday). The presentation during the mid-semester briefing/meeting is today.

Anyway, it went well actually. With some people laughing at us at the beginning before we started for some strange reason which we both cannot comprehend. But they liked the video a lot - which is attributed to CT's fantastic skills in creating the video and JL's interesting music.

Anyway, maybe we're making another one..?



Tuesday, 11 December 2007
ReachOut - Beyond Social Services is today. We went over to NTU Alumni Clubhouse in the morning and prepared for the games. For my "Amazing Scientific Race" station, I was with Harold and we shifted indoors due to the threat of rain. We talked about gravity and air resistance in the form of a fun game, which consisted them of throwing paper airplanes to reach the furthest distance (further = more points). And they got points which they could claim for prizes. Although the kids were very energetic which was a good sign, though I'm not sure if the handling of them was very effective, with all the overlooking for certain things which they should not be doing.

Anyway, after the race, had a buffet lunch at 8 Degrees Restaurant (so familiar) and when back to IHPC for a movie screening of Ratatouille, in conjunction with the staff movie screening for December. Well, since I've not watched that movie, might as well sit in and enjoy myself. :)

At the end of the day, though we were all tired from all the activities, we sat in for an AC Xmas retreat and enjoyed a bit before heading home.





Wednesday, 12 December 2007
Back to work. We started the day with manually calibrating the 4 projectors and learnt a bit about projector keystones, the effect is has when projecting while tilting up or down, as well as how the 4 tiled projectors were set up.

It took a lot of fine-tuning and adjusting before we managed to get the projectors more or less aligned. So now we have 4 screens where we can drag our windows on - which gets confusing sometimes, because I'm so used to drawing on a reversed canvas for the shape detection that when I draw on the normal canvas, I keep moving in the wrong way.

Oh well, gotta get used to it. Anyway, Kevin briefed us that we have the SAB presentation on the 8th of January 2008. We reviewed our milestones and projected end products and decided to give the game a while more before we move on to developing the HCI. However, this would mean that we will leave the game at a certain state where it is stable enough before moving on and coming back to it later to refine it. Oh well, few more days of the game code, gotta work harder!

Now focusing on point within a polygon detection. With the previous code for circle detection, it is possible to find the center of the circle to match the center of the object drawn. However, with a polygon, it is virtually impossible to find the center of it as there is no knowning before the detection, the number of corners the polygon will have. But some people will ask, why so? If the user draws (approximately) 4 right angles, it should relate to a rectangle/square, right? Or a shape with 3 corners would result in a triangle, won't it?

Not so! As the user's hand is not necessarily stable and the camera may not exactly capture light in a straight line. Result? A square with 4 right angles but more than 4 points, or a triangle with 4 points. - totally unpredictable.

So, without being able to find the fixed center of a n-gon without invoking very complicated and resource intensive mathematics, how can we find the center of a polygon, if possible, or to find out if a point is within the polygon, given a series of points/coordinates?

The Solution - I'm working on it!



Thursday, 13 December 2007
Today is a holiday. I spent the better half of the day studying for SCJP.



Friday, 14 December 2007
Okay. I'm lagging behind in my postings. Let me recall / summarize the things I've done for today.

Doing more research on Wednesday's problem. Searching and researching. Well, there are numerous interesting links, including a Fortan code written by someone a long time ago. Things like Mathlab and other related programs/framworks do repeatedly resurface in the search results, though it is highly likely using another program altogether would fix the problem.

Determination finally paid off, and towards the end of the day, I've finally found a suitable method. Well, it is not surprising that the C code solution is written by the same person who had written that Fortan code a long time ago. Well, looks like he's very kind to redo it in C, since majority of people use C/C++ out there.

http://softsurfer.com/Archive/algorithm_0103/algorithm_0103.htm


Well, let me do a summary of the algorithm here. But for more detailed information and the code implementation, please feel free to visit the website above. So, without further ado, the algorithm, which is called "The Crossing Number", goes something like this:

Accepting an argument for the single point (P) to be checked if it is inside the polygon, and an array (and where array[n] == array[0]) of all the points, it will draw a line from P, towards the edge of the canvas, towards the direction where x = infinity while keeping y constant (i.e. towards the right, parallel to the x-axis on a x/y graph). It then traverses the array and for every two points (i.e. Polygon Boundary Edge) , it determines if the line will cut across it. It then counts the total number of times the line passes over the entire polygon boundary. If the total number is even, then the point is outside of the polygon, else it is inside.

Pretty ingenious right? Using the knowledge of this new found methodology, I proceeded to manipulate it for my own selfish means and finally overcome the problem of detecting a point inside/outside an n-gon, which was resurfacing in my mind frequently for quite a while now.

Another thing I've learnt (although it is quite a while back) is that the coordinates (0,0) of the image is actually the top right corner, not the initial top left corner I have always assumed. Probably because during the circle detection, I was using an unflipped version of the canvas, causing everything to have a mirrored effect.

Okay, that's all for today. Hope you enjoyed reading.

Reflection of the Week:
I'm not sure if I have mentioned it previously, but I joined a Yahoo! Group regarding OpenCV as well as thronged through many forums and websites to search for tried and tested (and even untried and untested) methods to solve my problems. One thing I've noticed in all my surfings, including surfings from the past 3 to 5 years (5 being my first arrival to the Wired), is the lack of initiative that exist in there. Well, let me say that I am not stereotyping by saying that everyone inside a forum or user group has no initiative, but rather, a small number of people (and their outstanding incidents) have got me wondering if these people joined the group just to ask/demand/expect for answers. Although the way they ask their question may be slightly rude and demanding, the other great members inside the forums tap on their pool of patience and knowledge to try to answer them thoroughly and patiently.

What are the incidents, one might ask? Well, it usually goes along the lines of:

"I am developing [project details] and have an error. Can someone help me out? [insert entire source code here, consisting of a/several complex class(es)]" or "Can someone tell me the answer to [insert a question that has already been answered by other earlier threads, or can be easily found by searching Google]"

Well, it is true that forums and user groups are a source of information - to find solutions to problems, but should we be abusing it by pasting our entire source code (or worse, only a portion of the source code with no explanation and expect others to know the rest) there and expecting people to scan through the entire codes to understand the logic and find out what is wrong? Or demanding a quick answer to their problems which can easily be solved if they attempted to try (such as by looking at the API available online)?

IMHO, if there were at least attempts to try to understand their problem and only ask questions towards a narrower scope, it would have been much more easier and quicker for people to respond. Anyway, who would be inclined to find problems in codes amount up to 1000 lines with no incentive in return?

Perhaps, a better way to put it would be:

"I am developing [project details] and have encountered a problem which I cannot seem to comprehend. I've checked the server logs and it mentions that I have an buffer overflow thrown on line 35 (highlighted in red). I did a search on the method being called and did not notice anything wrong with the return type, neither does it throw any checked exceptions which I am supposed to handle. Could it be that the variable passed in as the argument during the for-loop is null or of wrong type? I know it might be tedious, but can someone kindly help me out, please? [insert source code of the method which the error occurs in and any related methods.]"

And of course, a little thank you after the answer has been posted and an update of the problem solving is appreciated, to show that their hard work and time is not wasted after all. Well, perhaps after going into that level of detail to state their problem within a narrower scope, they themselves would have been able to notice the error and solve the bug in their code before they even hit the "post thread" button.
Thankfully, only a small handful of people behave like the former; the rest behave in a much more matured and well-mannered fashion.

Negative online etiquette aside, I found many people at these forums or groups helpful and passionate to share their knowledge. Perhaps they are the ones, whose posts we should also value more, who make the forums a good place to hang out and learn. :)


Ciao for Week 9!

No comments: