Re: Circle-line intersection

From: Johannes Bergmark (johannes.bergmark_at_bredband.net)
Date: 12/04/04


Date: 4 Dec 2004 13:47:24 -0800

Hehe. The equation I wrote is correct, as you said:
t^2*(Dx^2 + Dy^2) + t*(2*Ax*Dx + 2*Ay*Dy) - R^2 + Ay^2 + Ax^2 = 0
but when I converted it to an equation of the second degree I forgot
an expression (Dx^2 + Dy^2). ;D
It will look like this (sqrt = square root of):

      Ax*Dx + Ay*Dy (Ax*Dx + Ay*Dy)^2 Ax^2 + Ay^2 - R^2
t = - ------------- +- sqrt(----------------- - ------------------)
       Dx^2 + Dy^2 (Dx^2 + Dy^2)^2 Dx^2 + Dy^2

Sigh, sigh. Now I'm glad it is correct thanks to you.

I'm doing this as a hobby programmer. Maybe there are easier ways, but
for me it's fun to solve this myself, and the purpose of this equation
is to compare two vectors (which has the same angles but different
origins). The vector which has the lowest 't' value above 0 is the
vector which first intersects the circle.
I'm planning a circle-circle collision-detection algorithm which tells
the user where the first collision-point is, and the vectors in this
equation has the same angle as the moving vector of the circle, but
the origins is at the both sides of the circle, these two are needed
because if I'd only one, the actual collision of the circles may miss.
But this will not work if I take a bigger circle to collide with a
smaller one because of the radius of the smaller one is lesser than
the distance between the two vectors at the bigger circle. Therefore I
made a rule to always check smaller circles against bigger ones (and
not vice versa).

Hope you understand my theory, and thank you for reading through and
comment everything.

/Johannes



Relevant Pages