Learn R Programming

affiner (version 0.1.3)

transform1d: 1D affine transformation matrices

Description

transform1d(), reflect1d(), scale2d(), and translate1d() create 1D affine transformation matrix objects.

Usage

transform1d(mat = diag(2L))

project1d(point = as_point1d("origin"), ...)

reflect1d(point = as_point1d("origin"), ...)

scale1d(x_scale = 1)

translate1d(x = as_coord1d(0), ...)

Value

A 2x2 post-multiplied affine transformation matrix with classes "transform1d" and "at_matrix"

Arguments

mat

A 2x2 matrix representing a post-multiplied affine transformation matrix. The last column must be equal to c(0, 1). If the last row is c(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 1x1 matrix we'll quietly add a final column/row equal to c(0, 1).

point

A Point1D object of length one representing the point you with to reflect across or project to or an object coercible to one by as_point1d(point, ...) such as "origin".

...

Passed to as_coord1d().

x_scale

Scaling factor to apply to x coordinates

x

A Coord1D object of length one or an object coercible to one by as_coord1d(x, ...).

Details

transform1d()

User supplied (post-multiplied) affine transformation matrix

.
reflect1d()

Reflections across a point.

scale1d()

Scale the x-coordinates by multiplicative scale factors.

translate1d()

Translate the coordinates by a Coord1D class object parameter.

transform1d() 1D affine transformation matrix objects are meant to be post-multiplied and therefore should not be multiplied in reverse order. Note the Coord1D class object methods auto-pre-multiply affine transformations when "method chaining" so pre-multiplying affine transformation matrices to do a single cumulative transformation instead of a method chain of multiple transformations will not improve performance as much as as it does in other R packages.

To convert a pre-multiplied 1D affine transformation matrix to a post-multiplied one simply compute its transpose using t(). To get an inverse transformation matrix from an existing transformation matrix that does the opposite transformations simply compute its inverse using solve().

Examples

Run this code
p <- as_coord1d(x = sample(1:10, 3))

# {affiner} affine transformation matrices are post-multiplied
# and therefore should **not** go in reverse order
mat <- transform1d(diag(2)) %*%
         scale1d(2) %*%
         translate1d(x = -1)
p1 <- p$
  clone()$
  transform(mat)

# The equivalent result appyling affine transformations via method chaining
p2 <- p$
  clone()$
  transform(diag(2))$
  scale(2)$
  translate(x = -1)

all.equal(p1, p2)

Run the code above in your browser using DataLab