intersection_sphere_line
- compas.geometry.intersection_sphere_line(sphere, line)[source]
Computes the intersection of a sphere and a line.
- Parameters:
- sphere[point, radius]
A sphere defined by a point and a radius.
- line[point, point] |
compas.geometry.Line
A line defined by two points.
- Returns:
- tuple[[float, float, float], [float, float, float]] | [float, float, float] | None
Two points (if the line goes through the sphere), one point (if the line is tangent to the sphere), or None (otherwise).
Notes
There are 3 cases of sphere-line intersection:
they intersect in 2 points
they intersect in 1 point (line tangent to sphere), or
they do not intersect.
Examples
>>> from compas.tolerance import TOL
>>> sphere = (3.0, 7.0, 4.0), 10.0 >>> line = (1.0, 0, 0.5), (2.0, 1.0, 0.5) >>> x1, x2 = intersection_sphere_line(sphere, line)
>>> TOL.is_allclose(x1, [11.634, 10.634, 0.500], atol=1e-3) True >>> TOL.is_allclose(x2, [-0.634, -1.634, 0.50], atol=1e-3) True