A ray is a directed line that starts at a given point and extends to infinity. As such it does not have a magnitude (like a vector) but only a beginning and a direction. A ray is considered to be degenerate if constructed be two points that are equal (and thus have no direction). Rays can be flipped by taking their negative

ray(..., default_dim = 2)

is_ray(x)

as_ray(x)

is_segment(x)

Arguments

...

Various input. See the Constructor section.

default_dim

The dimensionality when constructing an empty vector

x

A vector of rays or an object to convert to it

Value

An euclid_ray vector

Constructors

2 and 3 dimensional rays

  • Providing two points will construct rays starting at the first point and going through the second

  • Providing a point and a vector will construct rays starting at the point and moving in the direction of the vector.

  • Providing a point and a direction will construct rays starting at the point and moving in the given direction.

  • Providing a point and a line will construct rays starting at the point and moving in the direction of the line. Note that the point does not have lie on line.

Examples

# Construction p <- point(sample(10, 3), sample(10, 3)) r <- ray(p[1], p[2:3]) r
#> <2D rays [2]> #> [1] <x:2, y:7, dx:2, dy:2> <x:2, y:7, dx:7, dy:-3>
plot(p, pch = c(16, 17, 17))
ray(p, -as_vec(p))
#> <2D rays [3]> #> [1] <x:2, y:7, dx:-2, dy:-7> <x:4, y:9, dx:-4, dy:-9> <x:9, y:4, dx:-9, dy:-4>
ray(p, direction(7, -2))
#> <2D rays [3]> #> [1] <x:2, y:7, dx:7, dy:-2> <x:4, y:9, dx:7, dy:-2> <x:9, y:4, dx:7, dy:-2>
ray(p, line(3, 10, -8))
#> <2D rays [3]> #> [1] <x:2, y:7, dx:10, dy:-3> <x:4, y:9, dx:10, dy:-3> <x:9, y:4, dx:10, dy:-3>
# Flip direction -r
#> <2D rays [2]> #> [1] <x:2, y:7, dx:-2, dy:-2> <x:2, y:7, dx:-7, dy:3>
# Convert to vector, direction, or lines as_vec(r)
#> <2D vectors [2]> #> [1] <x:2, y:2> <x:7, y:-3>
#> <2D directions [2]> #> [1] <dx:2, dy:2> <dx:7, dy:-3>
as_line(r)
#> <2D lines [2]> #> [1] <a:-2, b:2, c:-10> <a:3, b:7, c:-55>