Intersections

Methods are provided to find intersections between all the specific subtypes of curve (i.e., not those with an externally provided parameterization). 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

from cxregions import *
Detected IPython. Loading juliacall extension. See https://juliapy.github.io/PythonCall.jl/stable/compat/#IPython

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

c = Circle(0, 1)
a = Arc(1+1j, 0, 1-1j)
b = Arc(1j, 1, -1j)

print(f"intersection of c and a: {c.intersect(a)}")
b_and_c = b.intersect(c)
print(f"type of b ∩ c:   {type(b_and_c)}")
print(f"is b ∩ c approximately b?   {b.isapprox(b_and_c)}")
intersection of c and a: [0.5-0.8660254j 0.5+0.8660254j]
type of b ∩ c:   <class 'cxregions.curves.Arc'>
is b ∩ c approximately b?   True

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

l = Line(1j, 1+1j)
s = Segment(-2, 2+2j)
print(f"intersection of l and s:        {l.intersect(s)}")
print(f"intersection of l and s + 2j:   {l.intersect(s + 2j)}")
print(f"intersection of s and Segment(-4-1j, 1j):   {s.intersect(Segment(-4-1j, 1j))}")
intersection of l and s:        [0.+1.j]
intersection of l and s + 2j:   []
intersection of s and Segment(-4-1j, 1j):   Segment from (-2+0j) to 1j
L = Line(1/2, 1/2+1j)    # line through 0.5 and 0.5+1i
c = L.inv()    # a circle
print(f"intersection of L and c:   {L.intersect(c)}")
intersection of L and c:   [0.5+0.8660254j 0.5-0.8660254j]