Advertisement

Ellipse-Line ColDet (2D)

Started by June 23, 2003 06:37 PM
5 comments, last by free lancer 21 years, 7 months ago
Uhh...how do I do it? With time integration, I mean. I know how to do line-line coldet, and I have actually done 3D ellipsoid-polygon coldet, but I need a tutorial that focuses on 2D ellipse-line coldet specifically. Basically, the ellipse is moving, and the line is not. I also need the ellipse to slide over the line (although I think I know how to do this). Thanks.
I would think this would be very similar to te 3D ellipsiod/polygon test. you make the line relative to the ellispse orietnation, and then relative to a unit circle, by scaling the line''s end points with the ellipse size. And do a moving circle/line test.


//------------------------------// inputs//------------------------------ellipse (p, v, rx, ry, angle) //position, velocity, radiusx, radiusy, angle of rotationline1   (p1, p2) // end points//------------------------------// temporary//------------------------------line2   (p1, p2)  // line in the ellipse coord systemcircle  (p, v, r) // normalised ellipsecontact1(p, n)    // contact in the ellipse coord system//------------------------------// output//------------------------------contact2(p, n) // contact in the world coord system


//---------------------------------// calculate line relative to ellipse coord system//---------------------------------line2.p1 = (line1.p1 - ellispe.p);line2.p2 = (line1.p2 - ellispe.p);Rotate(line2.p1, -ellispe.angle);Rotate(line2.p2, -ellipse.angle);line2.p1.x /= ellipse.rx;line2.p1.y /= ellipse.ry;//---------------------------------// calculate the normalised ellipse, which is a unit circle// centred at the origin//---------------------------------circle.p = (0.0f, 0,0f);circle.r = 1.0f;circle.v = ellipse.v;circle.v.x /- ellipse.rx;circle.v.y /- ellipse.ry;circle.v.Normalise();//---------------------------------// test intersection in ellipse coord system//---------------------------------line_circle_intersect(line2, circle, contact1);//---------------------------------// convert contact in world coord system//---------------------------------contact2.n.x = contact1.n.x * ellipse.rx;contact2.n.y = contact1.n.y * ellipse.ry;Rotate(contact2.n, ellipse.angle);contact2.n.Normalise();contact2.p.x = contact1.p.x * ellipse.rx;contact2.p.y = contact1.p.y * ellipse.ry;Rotate(contact2.p, ellipse.angle);contact2.p += ellipse.p;

Everything is better with Metal.

Advertisement
Is the ellipse rotating as it is moving?

If so, you probably have to use a numerical method.

If not, there is a pretty easy analytical solution. Find the point on the ellipse where the slope is equal to the slope of the line. This is the point that will be colliding with the line first. You can then do a simple trajectory-line collision detection. Even if the trajectory is not linear, this will work, as long as the ellipse is not rotating.

Cédric
Just what I needed. Thanks guys!
quote:
Original post by cedricl
Is the ellipse rotating as it is moving?

If so, you probably have to use a numerical method.

If not, there is a pretty easy analytical solution. Find the point on the ellipse where the slope is equal to the slope of the line. This is the point that will be colliding with the line first. You can then do a simple trajectory-line collision detection. Even if the trajectory is not linear, this will work, as long as the ellipse is not rotating.

Cédric


that is fine for an infinite plane, but with end-points, it's trickier. An analytical method could still be applied though, it's just a matter of dealing with ellipses against points. What you can do in that case is, instead of testing a moving ellipse against a point, you test a moving point against an ellipse (with the point velocity being the opposite of the ellipse velocity, obviously). It would be like a ray/ellipse test. probably easier to visualise.

Infinite planes would be OK if you partitioned your 2D space in a BSP tree, or such, but with a 'line soup', you might get into trouble.

Oh, and this algo (which I never tried, but that's the way I've seen it done for 3D triangle-ellipsoid tests) deals with rotating ellipses.

As a precaution, You might want to start testing the algorithm with circles first (rx = ry = 1, then rx = ry = r), then ellipses with no rotations (angle = 0), and then try with rotations. The problem with ellipses rotating, is, if they are rather fin, they might intersect already. Not sure how you want to deal with those cases.

for 3D, see

ftp://ftp.fluidstudios.com/pub/FluidStudios/CollisionDetection/Fluid_Studios_Generic_Collision_Detection_for_Games_Using_Ellipsoids.pdf


[edited by - oliii on June 24, 2003 8:15:17 PM]

Everything is better with Metal.

just one more note,

On many collision algorithm, you can ease the test by simplifying one of the shape, especially with dynamic tests (involving velocities or displacements). Like a moving sphere against a moving cylinder. It would end up being a ray-capsule (cylinder with spherical ends) intersection test. Much easier. Two moving sphere test would be equivalent to a large static sphere of radius r1+r2 against a ray. ect...

Everything is better with Metal.

Advertisement
quote:
Original post by oliii
quote:
Original post by cedricl
for 3D, see

ftp://ftp.fluidstudios.com/pub/FluidStudios/CollisionDetection/Fluid_Studios_Generic_Collision_Detection_for_Games_Using_Ellipsoids.pdf


Heh, this is actually what I've been using up until now, but I'm having enough trouble just getting a working circle-line collision test working

Hmmm...if I posted some code, would anyone be willing to take a peek at it and see if I'm doing it right? (which I'm not, cos it doesn't work).

[edited by - free lancer on June 25, 2003 6:23:13 AM]

This topic is closed to new replies.

Advertisement