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> c = Circle(0,1)
Circle{Complex{Float64}} in the complex plane:
centered at (0.0 + 0.0im) with radius 1.0, positively oriented
julia> a = Arc(1+1im,0,1-1im)
Arc{Complex{Float64}} in the complex plane:
fraction 0.5 of (Circle(1.0+0.0im,1.0,ccw)) starting at 0.25
julia> intersect(c,a)
2-element Array{Complex{Float64},1}:
0.5 - 0.8660254037844386im
0.5 + 0.8660254037844386im
julia> b = Arc(1im,1,-1im)
Arc{Complex{Float64}} in the complex plane:
fraction 0.5 of (Circle(0.0+0.0im,1.0,cw)) starting at 0.75
julia> intersect(c,b)
Arc{Complex{Float64}} in the complex plane:
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> l = Line(1im,1+1im)
Line{Complex{Float64}} in the complex plane:
through (0.0 + 1.0im) parallel to (1.0 + 0.0im)
julia> s = Segment(-2,2+2im)
Segment{Complex{Float64}} in the complex plane:
from (-2.0 + 0.0im) to (2.0 + 2.0im)
julia> intersect(l,s)
1-element Array{Complex{Float64},1}:
0.0 + 1.0im
julia> intersect(l,s+2im)
0-element Array{Any,1}
julia> intersect(s,Segment(-4-1im,1im))
Segment{Complex{Float64}} in the complex plane:
from (-2.0 + 0.0im) to (0.0 + 1.0im)
Here is the intersection of a polygon with a segment.
julia> box = [1-1im,3-1im,3+1im];
julia> plus = Polygon([box;1im*box;-box;-1im*box])
Polygon with 12 vertices:
1.0 - 1.0im, interior angle 1.5⋅π
3.0 - 1.0im, interior angle 0.5⋅π
3.0 + 1.0im, interior angle 0.5⋅π
1.0 + 1.0im, interior angle 1.5⋅π
1.0 + 3.0im, interior angle 0.5⋅π
-1.0 + 3.0im, interior angle 0.5⋅π
-1.0 + 1.0im, interior angle 1.5⋅π
-3.0 + 1.0im, interior angle 0.5⋅π
-3.0 - 1.0im, interior angle 0.5⋅π
-1.0 - 1.0im, interior angle 1.5⋅π
-1.0 - 3.0im, interior angle 0.5⋅π
1.0 - 3.0im, interior angle 0.5⋅π
julia> s = Segment(-3-2im,2+2im)
Segment{Complex{Float64}} in the complex plane:
from (-3.0 - 2.0im) to (2.0 + 2.0im)
julia> z = intersect(plus,s)
2-element Array{Any,1}:
1.0 + 1.2000000000000002im
-1.75 - 1.0im
julia> plot(plus);
julia> plot!(s);
julia> scatter!(Complex.(z))
Plot{Plots.GRBackend() n=3}