skspatial.objects.Cylinder.intersect_line¶
- Cylinder.intersect_line(line: Line, n_digits: Optional[int] = None, infinite: bool = True) Tuple[Point, Point] [source]¶
Intersect the cylinder with a 3D line.
By default, this method treats the cylinder as infinite along its axis (i.e., without caps).
- Parameters
- lineLine
Input 3D line.
- n_digitsint, optional
Additional keywords passed to
round()
. This is used to round the coefficients of the quadratic equation.- infinitebool
If True, the cylinder is treated as infinite along its axis (i.e., without caps).
- Returns
- point_a, point_b: Point
The two intersection points of the line with the cylinder, if they exist.
- Raises
- ValueError
If the line is not 3D. If the line does not intersect the cylinder at one or two points.
References
https://mrl.cs.nyu.edu/~dzorin/rendering/lectures/lecture3/lecture3.pdf
Examples
>>> from skspatial.objects import Line, Cylinder
>>> cylinder = Cylinder([0, 0, 0], [0, 0, 1], 1) >>> line = Line([0, 0, 0], [1, 0, 0])
Intersection with an infinite cylinder.
>>> cylinder.intersect_line(line) (Point([-1., 0., 0.]), Point([1., 0., 0.]))
>>> line = Line([1, 2, 3], [1, 2, 3])
>>> point_a, point_b = cylinder.intersect_line(line)
>>> point_a.round(3) Point([-0.447, -0.894, -1.342]) >>> point_b.round(3) Point([0.447, 0.894, 1.342])
>>> cylinder.intersect_line(Line([0, 0], [1, 2])) Traceback (most recent call last): ... ValueError: The line must be 3D.
>>> cylinder.intersect_line(Line([0, 0, 2], [0, 0, 1])) Traceback (most recent call last): ... ValueError: The line does not intersect the cylinder.
>>> cylinder.intersect_line(Line([2, 0, 0], [0, 1, 1])) Traceback (most recent call last): ... ValueError: The line does not intersect the cylinder.
Intersection with a finite cylinder.
>>> point_a, point_b = cylinder.intersect_line(Line([0, 0, 0], [0, 0, 1]), infinite=False)
>>> point_a Point([0., 0., 0.]) >>> point_b Point([0., 0., 1.])
>>> cylinder = Cylinder([0, 0, 0], [0, 0, 5], 1)
>>> point_a, point_b = cylinder.intersect_line(Line([0, 0, 0], [1, 0, 1]), infinite=False)
>>> point_a Point([0., 0., 0.]) >>> point_b Point([1., 0., 1.])