Intersection
Base.intersect
— Functionintersect(line_a::AbstractLine, line_b::AbstractLine) -> AbstractVector
Compute the intersection of two lines.
The intersection of two lines is a point.
Examples
julia> intersect(Line([0, 0], [1, 0]), Line([5, 5], [0, 1]))
2-element StaticArrays.SVector{2, Float64} with indices SOneTo(2):
5.0
0.0
intersect(plane::AbstractPlane, line::AbstractLine; kwargs...) -> AbstractVector
Compute the intersection point of a plane and a line.
An error is thrown if the plane and line are parallel (i.e., the plane normal is perpendicular to the line direction). The tolerances for this check can be passed as keyword arguments.
Examples
julia> intersect(Plane([0,0,0], [0, 0, 1]), Line([0, 0, 1], [1, 1, 1]))
3-element StaticArrays.SVector{3, Float64} with indices SOneTo(3):
-1.0
-1.0
0.0
julia> intersect(Plane([0,0,0], [0, 0, 1]), Line([0, 0, 1], [1, 1, 0]))
ERROR: ArgumentError: The line and plane are parallel.
Tolerances for the parallel check can be passed as keyword arguments.
julia> plane = Plane([0, 0, 0], [0, 0, 1]);
julia> line = Line([0, 0, 1], [1, 1, 1e-3]);
julia> intersect(plane, line)
3-element StaticArrays.SVector{3, Float64} with indices SOneTo(3):
-1000.0
-1000.0
0.0
julia> intersect(plane, line, atol=1e-3)
ERROR: ArgumentError: The line and plane are parallel.
julia> intersect(plane, line, rtol=1e-3)
ERROR: ArgumentError: The line and plane are parallel.
intersect(plane_a::AbstractPlane, plane_b::AbstractPlane; kwargs...) -> AbstractLine
Compute the intersection of two planes. The intersection of the planes is a line.
An error is thrown if the planes are parallel. The tolerances for this check can be passed as keyword arguments.
Examples
julia> plane_a = Plane([0, 0, 0], [0, 0, 1]);
julia> plane_b = Plane([5, 3, 2], [1, 0, 0]);
julia> intersect(plane_a, plane_b)
Line{3, Float64}([5.0, 0.0, 0.0], [0.0, 1.0, 0.0])
julia> plane_a = Plane([0, 0, 0], [0, 0, 1]);
julia> plane_b = Plane([1, 1, 1], [0, 0, -3]);
julia> intersect(plane_a, plane_b)
ERROR: ArgumentError: The planes are parallel.
julia> plane_a = Plane([0, 0, 0], [0, 0, 1]);
julia> plane_b = Plane([1, 1, 1], [0, 1e-2, 1]);
julia> intersect(plane_a, plane_b, atol=1e-3)
ERROR: ArgumentError: The planes are parallel.
intersect(circle::Circle, line::AbstractLine) -> Tuple{StaticArrays.SVector, StaticArrays.SVector}
Compute the intersection of a circle and a 2D line.
The intersection is returned as two points (which can be the same). An error is thrown if the circle and line do not intersect.
Examples
julia> circle = Circle([0, 0], 1);
julia> intersect(circle, Line([0, 0], [1, 0]))
([-1.0, 0.0], [1.0, 0.0])
julia> intersect(circle, Line([0, 1], [1, 0]))
([0.0, 1.0], [0.0, 1.0])
julia> intersect(circle, Line([0, 2], [1, 0]))
ERROR: ArgumentError: The circle and line do not intersect.
intersect(sphere::Sphere, line::AbstractLine) -> Tuple{StaticArrays.SVector, StaticArrays.SVector}
Compute the intersection of a sphere and a 3D line.
The intersection is returned as two points (which can be the same). An error is thrown if the sphere and line do not intersect.
Examples
julia> sphere = Sphere([0, 0, 0], 1);
julia> intersect(sphere, Line([0, 0, 0], [1, 0, 0]))
([-1.0, 0.0, 0.0], [1.0, 0.0, 0.0])
julia> intersect(sphere, Line([0, 0, -1], [1, 0, 0]))
([0.0, 0.0, -1.0], [0.0, 0.0, -1.0])
julia> intersect(sphere, Line([0, 1, 1], [1, 0, 0]))
ERROR: ArgumentError: The sphere and line do not intersect.