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
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
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:5, y:9, dx:-4, dy:-2> <x:5, y:9, dx:4, dy:-3>
plot(p, pch = c(16, 17, 17))
euclid_plot(r)
ray(p, -as_vec(p))
#> <2D rays [3]>
#> [1] <x:5, y:9, dx:-5, dy:-9> <x:1, y:7, dx:-1, dy:-7> <x:9, y:6, dx:-9, dy:-6>
ray(p, direction(7, -2))
#> <2D rays [3]>
#> [1] <x:5, y:9, dx:7, dy:-2> <x:1, y:7, dx:7, dy:-2> <x:9, y:6, dx:7, dy:-2>
ray(p, line(3, 10, -8))
#> <2D rays [3]>
#> [1] <x:5, y:9, dx:10, dy:-3> <x:1, y:7, dx:10, dy:-3> <x:9, y:6, dx:10, dy:-3>
# Flip direction
-r
#> <2D rays [2]>
#> [1] <x:5, y:9, dx:4, dy:2> <x:5, y:9, dx:-4, dy:3>
# Convert to vector, direction, or lines
as_vec(r)
#> <2D vectors [2]>
#> [1] <x:-4, y:-2> <x:4, y:-3>
as_direction(r)
#> <2D directions [2]>
#> [1] <dx:-4, dy:-2> <dx:4, dy:-3>
as_line(r)
#> <2D lines [2]>
#> [1] <a:2, b:-4, c:26> <a:3, b:4, c:-51>