compas.geometry.Rotation

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

Bases: compas.geometry.transformations.transformation.Transformation

Create a rotation transformation.

The class contains methods for converting rotation matrices to axis-angle representations, Euler angles, quaternion and basis vectors.

Parameters

matrix (4x4 matrix-like, optional) – A 4x4 matrix (or similar) representing a rotation.

Raises

ValueError – If the default constructor is used, and the provided transformation matrix is not a rotation.

Examples

>>> from compas.geometry import Frame
>>> f1 = Frame([0, 0, 0], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
>>> R = Rotation.from_frame(f1)
>>> args = False, 'xyz'
>>> alpha, beta, gamma = R.euler_angles(*args)
>>> xaxis, yaxis, zaxis = [1, 0, 0], [0, 1, 0], [0, 0, 1]
>>> Rx = Rotation.from_axis_and_angle(xaxis, alpha)
>>> Ry = Rotation.from_axis_and_angle(yaxis, beta)
>>> Rz = Rotation.from_axis_and_angle(zaxis, gamma)
>>> f2 = Frame.worldXY()
>>> f1 == f2.transformed(Rx * Ry * Rz)
True

Methods

concatenate(other)

Concatenate another transformation to this transformation.

concatenated(other)

Concatenate two transformations into one Transformation.

copy()

Returns a copy of the transformation.

decomposed()

Decompose the Transformation into its Scale, Shear, Rotation, Translation and Projection components.

euler_angles([static, axes])

Returns Euler angles from the Rotation according to specified axis sequence and rotation type.

from_axis_and_angle(axis, angle[, point])

Calculates a Rotation from a rotation axis and an angle and an optional point of rotation.

from_axis_angle_vector(axis_angle_vector[, …])

Calculates a Rotation from an axis-angle vector.

from_basis_vectors(xaxis, yaxis)

Creates a Rotation from basis vectors (= orthonormal vectors).

from_change_of_basis(frame_from, frame_to)

Computes a change of basis transformation between two frames.

from_data(data)

Creates a Transformation from a data dict.

from_euler_angles(euler_angles[, static, axes])

Calculates a Rotation from Euler angles.

from_frame(frame)

Computes the rotational transformation from world XY to frame.

from_frame_to_frame(frame_from, frame_to)

Computes a transformation between two frames.

from_json(filepath)

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

from_jsonstring(string)

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

from_list(numbers)

Creates a Transformation from a list of 16 numbers.

from_matrix(matrix)

Creates a Transformation from a 4x4 matrix-like object.

from_quaternion(quaternion)

Calculates a Rotation from quaternion coefficients.

inverse()

Returns the inverse transformation.

invert()

Invert this transformation.

inverted()

Returns the inverse transformation.

to_data()

Convert a Transformation object to a data dict.

to_json(filepath[, pretty])

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

to_jsonstring([pretty])

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

transpose()

Transpose the matrix of this transformation.

transposed()

Create a transposed copy of this transformation.

validate_data()

Validate the object’s data against its data schema (self.DATASCHEMA).

validate_json()

Validate the object’s data against its json schema (self.JSONSCHEMA).

Attributes

DATASCHEMA

The schema of the data of this object.

JSONSCHEMA

The schema of the JSON representation of the data of this object.

axis_and_angle

Returns the axis and the angle of the Rotation.

axis_angle_vector

Returns the axis-angle vector of the Rotation.

basis_vectors

Returns the basis vectors of the Rotation.

data

Return a Transformation object’s to a data dict.

determinant

The determinant of the matrix of the transformation.

dtype

The type of the object in the form of a “2-level” import and a class name.

guid

The globally unique identifier of the object.

list

Flattens the 4x4 transformation matrix into a list of 16 numbers.

name

The name of the object.

projection

The projection component of the transformation matrix.

quaternion

Returns the Quaternion from the Rotation.

rotation

The rotation component of the transformation matrix.

scale

The scale component of the transformation matrix.

shear

The shear component of the transformation matrix.

translation

The translation component of the transformation matrix.

translation_vector