Computer Science Canada Circle collision |
Author: | copthesaint [ Mon Mar 30, 2009 12:45 pm ] | ||
Post subject: | Circle collision | ||
The problem Is with drawing the black dots inside of the circle. This should be working (looking at the code) but I cant seem to get it to work. Help would be great and explination of what I did wrong.
sorry the code is so long had to stretch it to help debug. |
Author: | DemonWasp [ Mon Mar 30, 2009 1:32 pm ] | ||||||
Post subject: | RE:Circle collision | ||||||
Your CircleDetect method is, to say the least, slightly screwy. It looks like you're trying to use triangles to detect whether the cursor is inside a polygon approximating the circle, but I could be mistaken. If you're only planning on approximating circles, it's much easier to just use some simple arithmetic based on the mouse location and the circle-centre and radius than this method. The following returns true if the cursor is inside the circle:
When I replace the second set of nested loops with that line above, the method appears to do what you want - it draws red dots whenever you're outside the circle, and black dots whenever you're inside. Side note: you should only run check methods like that once; instead of:
Avoids calling the method twice, but accomplishes the same thing. Notice that we don't have to compare with true either - it's already true or false. |
Author: | copthesaint [ Mon Mar 30, 2009 10:45 pm ] | ||
Post subject: | RE:Circle collision | ||
Wow thanks. I Understand what you said and thanks. I think I was kinda over thinking for the progam ![]() Here is the program for anyone who may want this.
Ohh well at least I have learned something. |
Author: | DemonWasp [ Mon Mar 30, 2009 11:55 pm ] |
Post subject: | RE:Circle collision |
It's an important lesson, so let's make this abundantly clear: Simpler is Better. |