Computer Science Canada Oval Collision Detection |
Author: | richcash [ Sat Oct 14, 2006 11:21 pm ] | ||
Post subject: | Oval Collision Detection | ||
So, I'm trying to write the algorithm for oval collision detection to put in a tutorial I'm working on. I haven't spent too much time on it because I'm working on a lot of things at once. Here's what I have :
My problem is that it doesn't work. If you play around with the x and y radii values, the accuracy of the detection varies (sometimes being horrible!). I want to know if I have made an error in my calculations (or worst-case scenario, I'm completely on the wrong track, because I did derive it myself)? If the math is right, then does anyone have any ideas to make the function more accurate? {Below is my reasoning and logic behind the function, you don't need to read it. First, I found the angle between the two ovals' centers and the y-axis using tangent. Then, I wanted to find the point on the oval at that angle. So, I found the coordinates of the point at that angle for a unit circle using sine and cosine and then multiplied it by the x and y radius so it fits the oval. (I added the x and y of the center of the oval because my calculations were obviously for an oval at the origin.) Then I found the distance between that point on the oval and the centre of the oval, to find what I call an angular radius (probably not technical name). Then I used basic circle detection to check if the two "angular distances" of the ovals added up is greater than the distance between the center of the two ovals. If it is, then the ovals have collided.} |
Author: | TheOneTrueGod [ Sun Oct 15, 2006 1:33 am ] |
Post subject: | |
x**2 + y**2 = r**2 is the circular collision detection, but do you know WHY this is? If not, perhaps you should reconsider writing this tutorial. Nonetheless, here it goes. (x-dx/rx)**2 + (y-dy/ry)**2 = 1 I believe is the equation of an oval (Could be off based on the - dx, it could be a +dx, but whatever...). dx = delta X (x offset) dy = delta Y rx = x Radius ry = y Radius Design your algorithm based around this, and you'll be on the right track. |
Author: | richcash [ Sun Oct 15, 2006 1:06 pm ] | ||
Post subject: | |||
Quote: x**2 + y**2 = r**2 is the circular collision detection, but do you know WHY this is
Yes, I know that. I just prefer working with a variable like d1, d2, etc. while I'm debugging it. I can easily change it. Quote: (x-dx/rx)**2 + (y-dy/ry)**2 = 1
Thanks, TOTG! ![]() But I still need to find the angle to find a point on the first oval, don't I? Then I can check if that point is inside the second oval with your formula. My new function isn't much better :
Or is there a way to avoid finding the angle? Sorry, I don't have time to think too much, I'm working on something else aswell right now. I appreciate any help a lot. |