Still having trouble with swept line vs point...

Please don't post Bullet support questions here, use the above forums instead.
coderchris
Posts: 49
Joined: Fri Aug 18, 2006 11:50 pm

Still having trouble with swept line vs point...

Post by coderchris »

Iv posted a couple times before on the subject of determining time of impact between a moving line and point. Im getting closer and closer to getting it right each time, but still not quite there yet. I have established that I need to use the following formula to determine time t with points along the line A, B and velocities U, V, along with the stationary point C;

Also there is my attempt at solving it. I handled the perp by simply expanding the dot product.
Using my coefficients, it works perfectly when it is linear (the a coefficient is 0); however as soon as it is quadratic, I get unexpected results; Maybe someone could try working this out or checking my work to make sure my coefficients to feed the quadratic solver are correct?

0 = [(B + tV) - (A + tU)] . perp[C - (A + tU)]
= t^2 * [UxVy - UxUy]
+ t^1 * [-CxVy + CxUy + AxVy + ByUx - AxUy - AyUx + CyVx - CyVx - CyUx - AyVx - BxUy + AyUx + AxUy]
+ t^0 * [-ByCx + AyCx + AxBy - AxAy + CyBx - AxCy - AyBx + AxAy]

I tmust be my a coefficient that is wrong because like i said when a is 0, I get the correct TOI

THanks,
Chris
raigan2
Posts: 197
Joined: Sat Aug 19, 2006 11:52 pm

Re: Still having trouble with swept line vs point...

Post by raigan2 »

I'm afraid this may not be that helpful, as I'm solving it in a slightly different way.
Rather than using:
(C - (A + t*Av)) cross ((B + tBv) - (A + tAv)) = 0, t gives us parametric time of intersection

I do:
(C - (A + q*(B-A))) cross (vA + q*(vB-vA)) = 0, q gives us parametric point of intersection on seg AB

My quadratic is:

a = Dot( (B-A), Perp(vA-vB) )
b = Dot( vA, Perp(B-A) ) + Dot( (vA-vB), Perp(C-A) )
c = Dot( (C-A), Perp(vA) )

The code I copied this from works, but it's been almost a year since I touched it so I'm not sure why I did it this way.. also, in the above I seem to be using (vA-vB) rather than -(vB-vA), but again I'm not sure why.
coderchris
Posts: 49
Joined: Fri Aug 18, 2006 11:50 pm

Re: Still having trouble with swept line vs point...

Post by coderchris »

Thanks for the help; I suppose I could do it that way also, but how can i get the time from the parametric position?

Edit:
Actually, I just got the TOI formula working; for some reason i had a wrong sign in my quadractic solver :shock:
Its always the simple things...

But I would still like to know how I can get the time from position; I feel like the position will be more usefull to me than the time

Thanks
raigan2
Posts: 197
Joined: Sat Aug 19, 2006 11:52 pm

Re: Still having trouble with swept line vs point...

Post by raigan2 »

You can always use t to find q, or nice-versa.

If you know q, you can build a lineseg p0,p1 which sweeps out the path traced by the point of collision:
p0=(A + q*(B-A))
p1=(A+vA + q*(B+vB - (A+vA)))

You know C lies on this lineseg, so to find t you find the parametric position of C on p0,p1.

Similarly, if you know t but not q, you find the lineseg that describes the line at time t, and find the parametric position of C on that line.