Re: [Algorithms] Line Circle Collision Problem
Brought to you by:
vexxed72
From: Danny K. <dr...@we...> - 2005-06-14 16:36:50
|
You've got a minor problem in that the normal AB is ambiguous. Do you always want the clockwise normal? Or the nearest point B? Is the point A always definitely inside the circle? For the point on a vector v from A intersecting a circle radius r (assumed centered on (0,0) for simplicity), you're looking for t such that |a+tv|=r, so you have (a+tv).(a+tv)=r^2 a.a -r^2 + 2ta.v + t^2 v.v=0 All these are known except t, so you can solve this quadratic to find t, at which point B=a+tv. You'll generally get two answers (unless AC is a tangent): if A is inside the circle then one will be positive, the other negative - it's up to you to decide which of these you want (my guess is that you're looking for the one with the smallest absolute value, to judge by your description). Does that help? It's pretty simple, really. Danny (PS: Hello everybody - just joined the group recently. Nice to have a question I can answer so soon :) ) ----- Original Message ----- From: "Loki Istari" <mi...@gm...> To: <gda...@li...> Sent: Tuesday, June 14, 2005 5:09 PM Subject: [Algorithms] Line Circle Collision Problem Hi, given a circle at P which intersect a line segment CA, see picture pls..<http://www.iplayallday.com/test/drawing.gif> 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 |