Skip to contents

Coord2D is an R6::R6Class() object representing two-dimensional points represented by Cartesian Coordinates.

Active bindings

xyw

A three-column matrix representing the homogeneous coordinates. The first two columns are "x" and "y" coordinates and the third column is all ones.

x

A numeric vector of x-coordinates.

y

A numeric vector of y-coordinates.

Methods


Coord2D$new()

Usage

Coord2D$new(xyw)

Arguments

xyw

A matrix with three columns representing (homogeneous) coordinates. The first two columns represent x and y coordinates and the last column is all ones. Column names should be "x", "y", and "w".


Coord2D$permute()

Usage

Coord2D$permute(permutation = c("xy", "yx"))

Arguments

permutation

Either "xy" (no permutation) or "yx" (permute x and y axes)


Coord2D$print()

Usage

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

Arguments

n

Number of coordinates to print. If NULL print all of them.

...

Passed to format.default().


Coord2D$project()

Usage

Coord2D$project(line = as_line2d("x-axis"), ..., scale = 0)

Arguments

line

A Line2D object of length one representing the line you with to reflect across or project to or an object coercible to one by as_line2d(line, ...) such as "x-axis" or "y-axis".

...

Passed to project2d()

scale

Oblique projection scale factor. A degenerate 0 value indicates an orthogonal projection.


Coord2D$reflect()

Usage

Coord2D$reflect(line = as_line2d("x-axis"), ...)

Arguments

line

A Line2D object of length one representing the line you with to reflect across or project to or an object coercible to one by as_line2d(line, ...) such as "x-axis" or "y-axis".

...

Passed to reflect2d().


Coord2D$rotate()

Usage

Coord2D$rotate(theta = angle(0), ...)

Arguments

theta

An angle() object of length one or an object coercible to one by as_angle(theta, ...).

...

Passed to as_angle().


Coord2D$scale()

Usage

Coord2D$scale(x_scale = 1, y_scale = x_scale)

Arguments

x_scale

Scaling factor to apply to x coordinates

y_scale

Scaling factor to apply to y coordinates


Coord2D$shear()

Usage

Coord2D$shear(xy_shear = 0, yx_shear = 0)

Arguments

xy_shear

Horizontal shear factor: x = x + xy_shear * y

yx_shear

Vertical shear factor: y = yx_shear * x + y


Coord2D$translate()

Usage

Coord2D$translate(x = as_coord2d(0, 0), ...)

Arguments

x

A Coord2D object of length one or an object coercible to one by as_coord2d(x, ...).

...

Passed to as_coord2d(x, ...) if x is not a Coord2D object


Coord2D$transform()

Usage

Coord2D$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).


Coord2D$clone()

The objects of this class are cloneable with this method.

Usage

Coord2D$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

p <- as_coord2d(x = rnorm(100, 2), y = rnorm(100, 2))
print(p, n = 10)
#> <Coord2D[100]>
#>               x           y w
#>  [1,] 1.6127864  1.57061991 1
#>  [2,] 1.2145673  3.36046133 1
#>  [3,] 0.9432631  1.92914257 1
#>  [4,] 1.2044586  1.72784632 1
#>  [5,] 0.2437246 -0.44668003 1
#>  [6,] 1.3094621  2.06548664 1
#>  [7,] 1.4414580  0.90149110 1
#>  [8,] 1.4633367  1.36682182 1
#>  [9,] 2.2271271 -0.06365445 1
#> [10,] 2.9784549  4.64893203 1
pc <- mean(p) # Centroid
# method chained affine transformation matrices are auto-pre-multiplied
p$
  translate(-pc)$
  shear(x = 1, y = 0)$
  reflect("x-axis")$
  rotate(90, "degrees")$
  print(n = 10)
#> <Coord2D[100]>
#>                 x          y w
#>  [1,] -0.39933268 -0.9014031 1
#>  [2,]  1.39050873  0.4902193 1
#>  [3,] -0.04081003 -1.2124037 1
#>  [4,] -0.24210628 -1.1525045 1
#>  [5,] -2.41663263 -4.2877649 1
#>  [6,]  0.09553404 -0.7098607 1
#>  [7,] -1.06846150 -1.7418603 1
#>  [8,] -0.60313077 -1.2546509 1
#>  [9,] -2.03360705 -1.9213367 1
#> [10,]  2.67897943  3.5425775 1