Transformation

class compas.geometry.Transformation(matrix=None)[source]

Bases: Data

Class representing a general 4x4 transformation matrix.

It is the base class for transformations like Rotation, Translation, Scale, Reflection, Projection and Shear.

The class allows to concatenate Transformations by multiplication, to calculate the inverse transformation and to decompose a transformation into its components of rotation, translation, scale, shear, and perspective. The matrix follows the row-major order, such that translation components x, y, z are in the right column of the matrix, i.e. M[0][3], M[1][3], M[2][3] = x, y, z.

Parameters

matrix (list[list[float]], optional) – The 4x4 transformation matrix.

Attributes
  • scale (Scale, read-only) – The scale component of the transformation matrix.

  • shear (Shear, read-only) – The shear component of the transformation matrix.

  • rotation (Rotation, read-only) – The rotation component of the transformation matrix.

  • translation (Translation, read-only) – The translation component of the transformation matrix.

  • projection (Projection, read-only) – The projection component of the transformation matrix.

  • translation_vector (Vector, read-only) – The translation component of the transformation matrix as a translation vector.

  • basis_vectors (tuple[Vector, Vector], read-only) – The basis vectors from the rotation component of the transformation matrix.

  • list (list[float], read-only) – Flattens the 4x4 transformation matrix into a list of 16 numbers.

  • determinant (float, read-only) – The determinant of the matrix of the transformation.

Examples

>>> from compas.geometry import Frame
>>> f1 = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
>>> T = Transformation.from_frame(f1)
>>> Sc, Sh, R, Tl, P = T.decomposed()
>>> Tinv = T.inverse()

Methods

concatenate

Concatenate another transformation to this transformation.

concatenated

Concatenate two transformations into one Transformation.

copy

Returns a copy of the transformation.

decomposed

Decompose the Transformation into its components.

from_change_of_basis

Construct a change of basis transformation between two frames.

from_euler_angles

Construct a transformation from a rotation represented by Euler angles.

from_frame

Construct a transformation from world XY to frame.

from_frame_to_frame

Construct a transformation between two frames.

from_list

Creates a transformation from a list of 16 numbers.

from_matrix

Creates a transformation from a list[list[float]] object.

inverse

Returns the inverse transformation.

invert

Invert this transformation.

inverted

Returns the inverse transformation.

transpose

Transpose the matrix of this transformation.

transposed

Create a transposed copy of this transformation.

Inherited Methods

ToString

Converts the instance to a string.

from_data

Construct an object of this type from the provided data.

from_json

Construct an object from serialized data contained in a JSON file.

from_jsonstring

Construct an object from serialized data contained in a JSON string.

sha256

Compute a hash of the data for comparison during version control using the sha256 algorithm.

to_data

Convert an object to its native data representation.

to_json

Serialize the data representation of an object to a JSON file.

to_jsonstring

Serialize the data representation of an object to a JSON string.

validate_data

Validate the object's data against its data schema.

validate_json

Validate the object's data against its json schema.