10
$\begingroup$

Alright, I am programming a plugin for a game that requires me to get the closest point on a circle when all you have is a point B, which is outside of the circle, the radius of the circle, and the location of the center of the circle.

Say I have this situation: diagram

So, how would I be able to get the coordinates of point C? I need a formula that allows me to calculate those coordinates when I only know the radius of the circle and the coordinates of B. I sketched the line for ease of understanding, but all I start with is just the circle and point B. OH, one other thing, B isn't a static point, each time this calculation will be executed B will be at another position.

And, as a bonus (not really needed) would you care to show an example on how to do the same thing, but then when point B is inside the circle.

Thanks in advance!

  • 0
    That is useful to me too. But what if instead of a circle, it is an ellipse?2012-05-18
  • 0
    You should post this as a separate question, so that people can post answers to it using the answer box. I think you are going to have to solve a system of 2 quadratic equations: one is your equation of the ellipse $ax^2+by^2=1$, the other is $by(x-p)-ax(y-q)=0$ where $(p,q)$ is the point outside of ellipse. The second equation expresses the orthogonality of the vector $\langle x-p,y-q \rangle$ to the ellipse. The case of the circle is much easier because when $a=b$, the second equation is linear.2012-05-18
  • 0
    This can be "reduced" to solving a quartic equation. Note that there can be two local minima and two local maxima.2012-05-18
  • 0
    **Note** The two prior comments (of LK and RI) apply to Brad's comment (which was migrated from an answer).2012-05-18

1 Answers 1