Segment2D is an R6::R6Class() object representing a vector of two-dimensional line segments.
It inherits from Coord2D using the first endpoint p1 as the coordinate data, so all transformation methods (e.g. $rotate(), $translate()) and arithmetic operators work directly on the segment vector.
The full edge vector to the second endpoint is stored privately and kept consistent under every transformation.
Super class
Coord2D -> Segment2D
Methods
Segment2D$new()
Usage
Segment2D$new(xyw, vec)Segment2D$print()
Arguments
nNumber of segments to print. If
NULLprint all....Passed to
format.default().
Segment2D$transform()
Usage
Segment2D$transform(mat = transform2d())Arguments
matA 3x3 matrix representing a post-multiplied affine transformation matrix. The last column must be equal to
c(0, 0, 1). If the last row isc(0, 0, 1)you may need to transpose it to convert it from a pre-multiplied affine transformation matrix to a post-multiplied one. If a 2x2 matrix (such as a 2x2 post-multiplied 2D rotation matrix) we'll quietly add a final column/row equal toc(0, 0, 1).
Examples
p1 <- as_coord2d(x = c(0, 1), y = c(0, 0))
p2 <- as_coord2d(x = c(1, 1), y = c(0, 1))
s <- as_segment2d(p1, p2 = p2)
print(s)
#> <Segment2D[2]>
#> p1$x p1$y p2$x p2$y
#> [1,] 0 0 1 0
#> [2,] 1 0 1 1
s$p1
#> <Coord2D[2]>
#> x y w
#> [1,] 0 0 1
#> [2,] 1 0 1
s$p2
#> <Coord2D[2]>
#> x y w
#> [1,] 1 0 1
#> [2,] 1 1 1
s$mid_point
#> <Coord2D[2]>
#> x y w
#> [1,] 0.5 0.0 1
#> [2,] 1.0 0.5 1
length(s)
#> [1] 2
s[1]
#> <Segment2D[1]>
#> p1$x p1$y p2$x p2$y
#> 0 0 1 0
