coords.Coords.affine#

Coords.affine(mat, vec=None)#

Perform a general affine transformation.

Parameters#

mat: float array_like (3,3)

Matrix used in post-multiplication on a row vector to produce a new vector. The matrix can express scaling and/or rotation or a more general (affine) transformation.

vec: float array_like (3,)

Translation vector to add after the transformation with mat.

Returns#

Coords

A Coords with same shape as self, but with coordinates given by self * mat + vec. If mat is a rotation matrix or a uniform scaling plus rotation, the full operation performs a rigid rotation plus translation of the object.

Examples#

The module arraytools, here imported as at, provides a function to generate a rotation matrix.

>>> X = Coords([[0.0, 0.0],[1.0, 0.0],[1.0, 1.0],[0.0, 1.0]])
>>> S = np.array([[2.,0.,0.],[0.,3.,0.],[0.,0.,4.]]) # non-uniform scaling
>>> R = at.rotationMatrix(90.,2) # rotation matrix
>>> T = [20., 0., 2.] # translation
>>> M = np.dot(S,R)  # combined scaling and rotation
>>> print(X.affine(M,T))
[[20.   0.   2.]
 [20.   2.   2.]
 [17.   2.   2.]
 [17.   0.   2.]]