Coord2D
is an R6::R6Class()
object representing two-dimensional points
represented by Cartesian Coordinates.
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.
new()
Coord2D$new(xyw)
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".
permute()
Coord2D$permute(permutation = c("xy", "yx"))
permutation
Either "xy" (no permutation) or "yx" (permute x and y axes)
print()
Coord2D$print(n = NULL, ...)
n
Number of coordinates to print. If NULL
print all of them.
...
Passed to format.default()
.
project()
Coord2D$project(line = as_line2d("x-axis"), ..., scale = 0)
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.
reflect()
Coord2D$reflect(line = as_line2d("x-axis"), ...)
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()
.
rotate()
Coord2D$rotate(theta = angle(0), ...)
theta
An angle()
object of length one or an object coercible to one by as_angle(theta, ...)
.
...
Passed to as_angle()
.
scale()
Coord2D$scale(x_scale = 1, y_scale = x_scale)
x_scale
Scaling factor to apply to x coordinates
y_scale
Scaling factor to apply to y coordinates
shear()
Coord2D$shear(xy_shear = 0, yx_shear = 0)
xy_shear
Horizontal shear factor: x = x + xy_shear * y
yx_shear
Vertical shear factor: y = yx_shear * x + y
translate()
Coord2D$translate(x = as_coord2d(0, 0), ...)
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
transform()
Coord2D$transform(mat = transform2d())
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)
.
clone()
The objects of this class are cloneable with this method.
Coord2D$clone(deep = FALSE)
deep
Whether to make a deep clone.
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