views:

822

answers:

3

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?

A: 

Two points define a line L. Solve for an equation Cx + L = 0 where C is the equation of the circle. If I remember correctly :P Some more information here.

dirkgently
+9  A: 

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 )
Beska
We need a way in SO to make nice formulas!
Beska
yes... latex support, essentially --has been mentioned many times.
nlucaroni
+2  A: 

Use the center of the circle as a point of reference. Get the distance from the center point to your two points, then the radius of the circle. You can now draw a triangle between any three of those points (center, segment point, and circle edge.) Pythagoras can handle the rest.

Dave Swersky