Skip to content

Intersections

Methods are provided to find intersections between all the Specific subtypes. In the generic cases where the intersections consist of zero or more points, a vector of results is returned. In special circumstances of partially or wholly overlapping curves, a Curve subtype is returned.

There are also methods for finding the intersections between curves and paths, and between two paths. These return set unions over the curves of the path(s), returning a vector with complex element type or, if some overlaps occurred, mixed types.

Examples

Circles and Arcs intersect at zero, one, or two points, or as an Arc.

julia
julia> c = Circle(0, 1)
Circle{Float64} centered at (0.0 + 0.0im) with radius 1.0, positively oriented

julia> a = Arc(1+1im, 0, 1-1im)
Arc{Float64} fraction 0.5 of Circle(1.0+0.0im, 1.0, ccw) starting at 0.25

julia> intersect(c, a)
2-element Vector{ComplexF64}:
 0.5 - 0.8660254037844386im
 0.5 + 0.8660254037844386im

julia> b = Arc(1im, 1, -1im)
Arc{Float64} fraction 0.5 of Circle(0.0+0.0im, 1.0, cw) starting at 0.75

julia> intersect(c, b)
Arc{Float64} fraction 0.5 of Circle(0.0+0.0im, 1.0, cw) starting at 0.75

julia> ans  b
true

Segments and Lines intersect at zero or one point, or as a Line or Segment.

julia
julia> l = Line(1im, 1+1im)
Line{Float64} through (0.0 + 1.0im) parallel to (1.0 + 0.0im)

julia> s = Segment(-2, 2+2im)
Segment{Float64} from (-2.0 + 0.0im) to (2.0 + 2.0im)

julia> intersect(l, s)
1-element Vector{ComplexF64}:
 0.0 + 1.0im

julia> intersect(l, s + 2im)
Any[]

julia> intersect(s, Segment(-4-1im, 1im))
Segment{Float64} from (-2.0 + 0.0im) to (0.0 + 1.0im)
julia
julia>= Line(1/2, 1/2+1im)    # line through 0.5 and 0.5+1i
Line{Float64} through (0.5 + 0.0im) parallel to (0.0 + 1.0im)

julia> c = 1 /# a circle
Circle{Float64} centered at (1.0 - 2.7755575615628914e-17im) with radius 1.0, negatively oriented

julia> intersect(ℓ, c)
2-element Vector{ComplexF64}:
 0.5 + 0.8660254037844386im
 0.5 - 0.8660254037844386im