Line Circle Intersection Problem

Started by
4 comments, last by yanuart 18 years, 10 months ago
Hi, given a circle with radius r at P which intersect a line segment CA, see picture pls.. How can I get vector AB (line normal from A which intersect circle at B) ?? Before you think I'm asking this to answer my math homework, please rest assure that I'm not (okay, I kinda suck at math) :D, I'll use vector AB to push the circle so that it will always stays at the edge of the line.. it's for my game, in case you're wondering... The common line circle intersection/collision detection computes can't work in my case cause it needs two intersection point and calculates the push vector from a line normal that crosses the center of circle. Anyway.. any hint on how I can calculate (I'll follow up your hint, I hope i still got something left in my brain) that AB vector will be very appreciated thanks
Ride the thrill of your life
Play Motorama
Advertisement

but to see if a static circle intersects a static segment, you only need to see if the length of the projection of P onto CA is greater than r

assumuning C and A are the coordinate of the segment

C + ( dot(P-C, A-C)/|A-C|^2 ) * (A - C) is the projection of P onto CA

because

dot(P-C, A-C)/|A-C|^2 is letting C be the origin by subtracting C from all points

and finding (|P|*cos(angle of P using C as origin))/ |A|

so letting t = dot(P-C, A-C)/|A-C|^2
and again just find if |C+t(A-C)| < r and the circle intersects the segment



edit i misread what you were saying
It's not a problem wether to test the circle has collide with line segment or not. That I'm pretty much covered, all I need to find is either point B or vector AB.

Ride the thrill of your life
Play Motorama
well since

|C + t*(A-C)| = r is the point of intersection

|C + t * ( A-C)|^2 - r^2 = 0 is an equivilant expresion

since |V|^2 = dot(V, V)

|C + t * ( A-C)|^2 - r^2 = 0 is a quadratic expresion of t

solve for t using A and C as an infinite line perendicular to the origial

and plug the t's in back into C+t(A-C) to find the points of intersection

***just a note its not so clear but let A and C in this post be a perpendicular line to the original so C = (-C.y, C.x), A = (-A.y, A.x)



*** edit again theirs definatly something wrong with this. but if i think about it i cant figure it out myself right now. but try putting The perp into the intersect equation and see if you can come up with a way to spit out 2 numbers !
im not taking into account the center of the circle in what i did but i think the solution will be similar.

[Edited by - Raymond_Porter420 on June 14, 2005 1:26:41 PM]
from what you say I am assuming that you want AC and AB to be the samer length.
therefore
calculate distance of AC and call it u
(x - Ax)2 + (y - Ay)2 = u
but we can also say
(x - Px)2 + (y - Py)2 = d
where P is the center of the circle. so now its simply a matter of solving them
to get 2 terms.

i'm too tired to solve atm. i'll finish tommorow, but theres a starting point.
thx guys, I solved it ,
first we need to find the length of AB
|AB|=r-|PA|

to get the vector AB, we need a normal vector from AC and multiply it with the length we just calculate..

so simple.. i'm ashamed of myself :(
Ride the thrill of your life
Play Motorama

This topic is closed to new replies.

Advertisement