Jump to content
  • Advertisement
Sign in to follow this  
Deadlybones

Axis aligned ellipse collisions?

This topic is 2470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I have been googling this and searching the gamedev forums all day but I can't seem to find what I'm looking for. There are a lot of articles on ellipse collisions/intersections but most of them are for rotated ellipses too. I feel like there should be a simpler way of doing things and I don't think I need to read a 50 page document on how to do it haha.

What I'm trying to achieve, is that when two axis aligned ellipses are moving(lets call the ellipse A and ellipse B) intersect, if ellipse B is higher up then it will smoothly push up/slide past ellipse. If it is lower then it will do the opposite. I'm not sure if I have to find out where they intersect but if I do need to know that then I would like to be able to figure that out too

Some pseudo-code would be much appreciated. Thanks!

Share this post


Link to post
Share on other sites
Advertisement

There are a lot of articles on ellipse collisions/intersections but most of them are for rotated ellipses too


If the equations in the docs you're reading also work for rotated ellipses, why not just simplify them by replacing the rotation angles with 0 or 180 degrees?

If you absolutely promise that the two ellipses are not rotated relative to each other, then just find the line equation between the center points of the two ellipses, and then solve that equation for any one ellipse's equation to find points of intersection of that line on the ellipse. Then check if these points are on or inside the second ellipse (by replacing the x & y coordinates of the points in the ellipse equation and checking if the result is <= 0).

If you haven't done collision detection yourself before, it'll be useful if you read up the equations representing different shapes and try this exercise on paper and then programming it. Otherwise all physics engines have a collision detection module built-in, so you just need to give it the shapes and it'll do the rest. Box2d is one such physics engine, but I don't think it does ellipses yet.

Cheers
~dd~

PS: You will get two points per ellipse, since the line joining the centers will cut each ellipse in two places.
PPS: Let me know if you need some help on solving the ellipse equations

Share this post


Link to post
Share on other sites
I don't know what you two have been reading but you most certainly do not get two answers when checking collision with circles or axis aligned ellipses.

That is beccause circles and axis aligned ellipses are a special case that can be reduced to a very simple check

Lets say we have two circles. A and B

1. You sum their radius. colRadius=A::r+B::r.
2. You calculate their centers distance on both x and y axis. xdist=B::x-A::x and ydist=B::y-A::y
3. You calculate their overral distance by. oDist=sqrt(xdist*xdist+ydist*ydist)
4. If overral distance is smaller than the sum of their radius it is a collision. oDist<colRadius.
5. If you need the collision point it is A::x+xdist/2 and A::y+ydist/2

This can be modiefied to fit ellipses with a very simple trick.

Lets say we have two ellipses. A and B. Both are W as wide as they are tall.

1. You sum their smaller radius colRadius=A::r+B::r.(smaller radius now being the radius along the y axis)
2. You calculate their distance on both x and y axis. xdist=B::x-A::x and ydist=B::y-A::y
3. You calculate their overral distance by oDist=sqrt((xdist/W)*(xdist/W)+ydist*ydist).(we need to divide the xdist by W here to strech it collision area to be W as wide as it is tall.)
4. If overral distance is smaller than the sum of their radius it is a collision. oDist<colRadius.
5. If you need the collision point it is A::x+(xdist/2)*W and A::y+(ydist/2).(We need to multiply xdist it by W because we would otherwise get the collision point for a circle and not a W as wide ellipse).

Now you said that you would like them to push each other up/down respective of their position so they would slide over/under each other.

You can do that easily by moving them up/down respectivly by (sqrt(colRadius*(W*W)-(xdist*xdist))-10*W)/(2W)
That equation calculates the amount the upper one should go up and lower one should go down for them to barely not hit each other. I got it from a symbolic calculator by solving for x from colRadius=sqrt((xdist/W)*(xdist/W)+(ydist+2x)*(ydist+2x)) so it should be correct

Hope this is not too complicatedly explained. I have been awake for 16 hours now and I may not be the most comprihencible person when I'm tired.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!