Skip to contents

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

Active bindings

p1

A Coord2D object of the first endpoints.

p2

A Coord2D object of the second endpoints.

mid_point

A Coord2D object of the segment midpoints (computed on demand and cached until the next transformation).

Methods

Inherited methods


Segment2D$new()

Usage

Segment2D$new(xyw, vec)

Arguments

xyw

A matrix with three columns for homogeneous p1 coordinates. Column names should be "x", "y", and "w".

vec

A two-column matrix of edge vectors p2 - p1. Column names should be "x" and "y".


Segment2D$print()

Usage

Segment2D$print(n = NULL, ...)

Arguments

n

Number of segments to print. If NULL print all.

...

Passed to format.default().


Segment2D$transform()

Usage

Segment2D$transform(mat = transform2d())

Arguments

mat

A 3x3 matrix representing a post-multiplied affine transformation matrix. The last column must be equal to c(0, 0, 1). If the last row is c(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 to c(0, 0, 1).


Segment2D$clone()

The objects of this class are cloneable with this method.

Usage

Segment2D$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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