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.

See also

Other Geometries: circle(), direction(), iso_cube(), iso_rect(), line(), plane(), point(), segment(), sphere(), tetrahedron(), triangle(), vec(), weighted_point()

Other Curves: line(), segment()

Examples

# Construction
p <- point(sample(10, 3), sample(10, 3))
r <- ray(p[1], p[2:3])
r
#> <2D rays [2]>
#> [1] <x:3, y:3, dx:2, dy:6>  <x:3, y:3, dx:7, dy:-1>
plot(p, pch = c(16, 17, 17))
euclid_plot(r)


ray(p, -as_vec(p))
#> <2D rays [3]>
#> [1] <x:3, y:3, dx:-3, dy:-3>   <x:5, y:9, dx:-5, dy:-9>  
#> [3] <x:10, y:2, dx:-10, dy:-2>

ray(p, direction(7, -2))
#> <2D rays [3]>
#> [1] <x:3, y:3, dx:7, dy:-2>  <x:5, y:9, dx:7, dy:-2>  <x:10, y:2, dx:7, dy:-2>

ray(p, line(3, 10, -8))
#> <2D rays [3]>
#> [1] <x:3, y:3, dx:10, dy:-3>  <x:5, y:9, dx:10, dy:-3> 
#> [3] <x:10, y:2, dx:10, dy:-3>

# Flip direction
-r
#> <2D rays [2]>
#> [1] <x:3, y:3, dx:-2, dy:-6> <x:3, y:3, dx:-7, dy:1> 

# Convert to vector, direction, or lines
as_vec(r)
#> <2D vectors [2]>
#> [1] <x:2, y:6>  <x:7, y:-1>

as_direction(r)
#> <2D directions [2]>
#> [1] <dx:2, dy:6>  <dx:7, dy:-1>

as_line(r)
#> <2D lines [2]>
#> [1] <a:-6, b:2, c:12> <a:1, b:7, c:-24>