Skip to contents

intersection() is an S3 method that returns the intersection of two objects.

Usage

intersection(x, y, ...)

# S3 method for class 'Point1D'
intersection(x, y, ..., tolerance = sqrt(.Machine$double.eps))

# S3 method for class 'Line2D'
intersection(x, y, ..., tolerance = sqrt(.Machine$double.eps))

# S3 method for class 'Plane3D'
intersection(x, y, ..., tolerance = sqrt(.Machine$double.eps))

# S3 method for class 'Coord1D'
intersection(x, y, ..., tolerance = sqrt(.Machine$double.eps))

# S3 method for class 'Coord2D'
intersection(x, y, ..., tolerance = sqrt(.Machine$double.eps))

# S3 method for class 'Ellipse2D'
intersection(x, y, ..., tolerance = sqrt(.Machine$double.eps))

# S3 method for class 'Coord3D'
intersection(x, y, ..., tolerance = sqrt(.Machine$double.eps))

Arguments

x, y

The two objects to compute intersection for.

...

Passed to other methods (or ignored).

tolerance

Numerics with differences smaller than tolerance will be considered “equivalent”.

Value

A list of the object intersections (or NULL if no intersection). For Line2D-Ellipse2D intersections each list element is a Coord2D of length 2 (two crossing points), length 1 (tangent), or NULL (no intersection).

Details

affiner::intersection() has the same S3 signature as euclid::intersection() (so it shouldn't matter if one masks the other).

Examples

line1 <- as_line2d("x-axis")
line2 <- as_line2d("y-axis")
line3 <- as_line2d(a = 0, b = 1, c = 2) # y + 2 = 0
intersection(line1, line1)
#> [[1]]
#> <Line2D[1]>
#> a b c 
#> 0 1 0 
#> 
intersection(line1, line2)
#> [[1]]
#> <Coord2D[1]>
#> x y w 
#> 0 0 1 
#> 
intersection(line1, line3)
#> [[1]]
#> NULL
#> 

# Unit circle vs x-axis: two points at (1, 0) and (-1, 0)
circ <- as_ellipse2d(as_coord2d("origin"), r = 1)
intersection(circ, line1)
#> [[1]]
#> <Coord2D[2]>
#>       x             y w
#> [1,]  1  0.000000e+00 1
#> [2,] -1 -1.224647e-16 1
#> 

# Tangent: circle vs line y = 1 (touches top of circle)
line_top <- as_line2d(a = 0, b = 1, c = -1) # y - 1 = 0
intersection(circ, line_top)
#> [[1]]
#> <Coord2D[1]>
#>            x            y            w 
#> 6.123234e-17            1            1 
#> 

# No intersection: circle vs y = 2
line_above <- as_line2d(a = 0, b = 1, c = -2) # y - 2 = 0
intersection(circ, line_above)
#> [[1]]
#> NULL
#>