A segment is a finite directed line going from one point to another. If the two points are equal it is considered to be degenerate. A segment can be flipped be taking its negative.

segment(..., default_dim = 2)

as_segment(x)

## Arguments

... Various input. See the Constructor section. The dimensionality when constructing an empty vector A vector of segments or an object to convert to it

## Value

An euclid_segment vector

## Constructors

2 and 3 dimensional segments

• Providing two points will construct segments starting at the first point and ending at the second

• Providing a point and a vector will construct segments starting at the point and ending at the point defined by the start point plus the vector

## Examples

# Construction
p <- point(sample(4), sample(4))
s <- segment(p[1:2], p[3:4])
s
#> <2D segments >
#>  [<x:3, y:2>, <x:4, y:1>] [<x:1, y:3>, <x:2, y:4>]
plot(s)

segment(p[1:2], as_vec(p[3:4]))
#> <2D segments >
#>  [<x:3, y:2>, <x:7, y:3>] [<x:1, y:3>, <x:3, y:7>]
# Flip segments
-s
#> <2D segments >
#>  [<x:4, y:1>, <x:3, y:2>] [<x:2, y:4>, <x:1, y:3>]
# Segments can be converted to vectors, directions and lines
as_vec(s)
#> <2D vectors >
#>  <x:1, y:-1> <x:1, y:1>
as_direction(s)
#> <2D directions >
#>  <dx:1, dy:-1> <dx:1, dy:1>
as_line(s)
#> <2D lines >
#>  <a:1, b:1, c:-5>  <a:-1, b:1, c:-2>plot(s)
euclid_plot(as_line(s), lty = 2) 