I have a circle. Inside the circle is a point. I have a vector originating at this point. I’d like to know what point on the circle this vector intersects. Here is a drawing:
http://n4te.com/temp/circle.png http://n4te.com/temp/circle.png
The red dot is the point I am trying to determine.
I know these things: the center of the circle, the origin of the vector, and the direction of the vector.
I know this is basic stuff, but I’m still having trouble. Most of the Googlings bring me to line-circle collision, which is related but not quite the same. Thanks for any help you can provide!
Elementary vector algebra.
Solve
(A + kt - O)² = r²for scalart, choose positive root, andA + ktis your point.Further explanation:
.is dot product, ² for a vector is dot product of the vector with itself. Expand LHSThe quadratic is
k²t² + 2(k.(A - O))t + (A - O)² - r² = 0. In terms of your variables, this becomes(rayVX² + rayVY²)t² + 2(rayVX(rayX - circleX) + rayVY(rayY - circleY))t + (rayX - circleX)² + (rayY - circleY)² - r² = 0.