skspatial.objects.Circle.intersect_line¶
- Circle.intersect_line(line: Line) Tuple[Point, Point] [source]¶
Intersect the circle with a line.
A line intersects a circle at two points.
- Parameters
- lineLine
Input line.
- Returns
- point_a, point_bPoint
The two points of intersection.
- Raises
- ValueError
If the line does not intersect the circle.
References
http://mathworld.wolfram.com/Circle-LineIntersection.html
Examples
>>> from skspatial.objects import Circle, Line
>>> circle = Circle([0, 0], 1)
>>> circle.intersect_line(Line(point=[0, 0], direction=[1, 0])) (Point([-1., 0.]), Point([1., 0.]))
>>> point_a, point_b = circle.intersect_line(Line(point=[0, 0], direction=[1, 1]))
>>> point_a.round(3) Point([-0.707, -0.707])
>>> point_b.round(3) Point([0.707, 0.707])
>>> circle.intersect_line(Line(point=[1, 2], direction=[1, 1])) (Point([-1., 0.]), Point([0., 1.]))
If the line is tangent to the circle, the two intersection points are the same.
>>> circle.intersect_line(Line(point=[1, 0], direction=[0, 1])) (Point([1., 0.]), Point([1., 0.]))
The circle does not have to be centered on the origin.
>>> point_a, point_b = Circle([2, 3], 5).intersect_line(Line([1, 1], [2, 3]))
>>> point_a.round(3) Point([-0.538, -1.308])
>>> point_b.round(3) Point([5., 7.])
>>> circle.intersect_line(Line(point=[5, 0], direction=[1, 1])) Traceback (most recent call last): ... ValueError: The line does not intersect the circle.