R – the equation to calculate the distance from the end of a line segment to the edge of a circle


I have a circle with two points inside it that make up a line segment. How can I calculate the distance from one endpoint to the edge of the circle where the line would intersect it?

Best Solution

I think the easist way is to figure out where the intersection of the line and the circle is, then just calculate the distance from the line segment point with the intersection point.

So, say your circle is described by the equation

x^2 + y^2 = 5

and your line segment is points like

(1,3), (2,4)

First, you figure out the equation for the line that is directly over the segment, which, in this case, would be

y = x + 2

You then substitute this equation into the first equation, and you get

x^2 + (x+2)^2 = 5

Simplify this into

2x^2 + 4x - 1 = 0

and solve via the quadradic formula.

You now have the x coordinates of the two intersection points. From there, plug into the line equation to get the y coordinates. Then you can just do normal point distance calculation ala Pythagoras.

sqrt ( (x1 - x2)^2 + (y1 - y2)^2 )