Learn R Programming

affiner (version 0.1.3)

Coord2D: 2D coordinate vector R6 Class

Description

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

Arguments

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


Method 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".


Method permute()

Usage

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

Arguments

permutation

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


Method print()

Usage

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

Arguments

n

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

...

Passed to format.default().


Method 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.


Method 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().


Method 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().


Method 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


Method 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


Method 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


Method 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).


Method 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

Run this code
p <- as_coord2d(x = rnorm(100, 2), y = rnorm(100, 2))
print(p, n = 10)
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)

Run the code above in your browser using DataLab