at^2 + bt + c = 0.

a = Xv1 * ( Xv1 - 2 * Xv2 ) + Yv1 * ( Yv1 - 2 * Yv2 ) + Xv2 ^ 2 + Yv2 ^ 2

b = 2 * ( Xs1 * ( Xv1 - Xv2 ) + Xs2 * ( Xv2 - Xv1 ) + Ys1 * ( Yv1 - Yv2 ) + Ys2 * ( Yv2 - Yv1 ) )

c = Xs1 * ( Xs1 - 2 * Xs2 ) + Ys1 * ( Ys1 - 2 * Ys2 ) + Xs2 ^ 2 + Ys2 ^ 2 - ( R1 + R2 ) ^ 2

Solved.

Lot of mults. Be a bit slow :/ And I'll have to shift things closer to the origin, otherwise all those squares will overflow . . .

bleah. they'll overflow anyway. maybe I'll have to shift them down 8 bits too. Assuming max speed is 32 bits, and subpixel is 16 bits . . . then . . . if I want this to fit into 64 bits, I'd better restrict it to 30 bits of location. Yeah. I'd have to translate to near-origin and shift down at least three bits. eight would be good. Loss of precision, but at least I don't have to try to code 128-bit arithmetic! >_<

But, yeah. It's solved. Just compare the two roots. Not only that, but it tells you where they'll hit period, so I can integrate it into the AI for collision thingies.

now, how can I rig it to compute closest-approach? . . .
• Post a new comment

#### Error

default userpic