Question

I have a line with start point as P1(x1, y1) & end Point as P2(x2, y2). This line is from the center of circle. The circle radius is r. Need a simple equation to identify the circle line intersect point?

Was it helpful?

Solution

Assuming P1 is the center of the circle, first get the slope of the line, then follow it from P1 to distance r along that direction.

phi = atan2(y2-y1, x2-x1)
x = x1 + r * cos(phi)
y = y1 + r * sin(phi)

OTHER TIPS

The equation for a circle is (x-h)^2 - (y-k)^2 = r^2, where the center is (h, k) (which will end up being (0, 0) relative to your line)

Given two points, you can find the slope of the line, now you can plug it into the formula y = m*x + b.

You now have a system of two equations, solve for x or y in one equation, then plug that expression into the other equation and you will find the numeric value of the variable you did not solve for. You can then plug that back into the equation for a line and find the second variable.

Here is the general formula: http://mathworld.wolfram.com/Circle-LineIntersection.html

And some other answers: Circle line-segment collision detection algorithm?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top