Quaternion
- class compas.geometry.Quaternion[source]
Bases:
Geometry
A quaternion is defined by 4 components, X, Y, Z, and W.
- Parameters:
- wfloat
The scalar (real) part of a quaternion.
- xfloat
X component of the vector (complex, imaginary) part of a quaternion.
- yfloat
Y component of the vector (complex, imaginary) part of a quaternion.
- zfloat
Z component of the vector (complex, imaginary) part of a quaternion.
- namestr, optional
The name of the transformation.
- Attributes:
- wfloat
The W component of the quaternion.
- xfloat
The X component of the quaternion.
- yfloat
The Y component of the quaternion.
- zfloat
The Z component of the quaternion.
- wxyzlist[float], read-only
Quaternion as a list of float in the ‘wxyz’ convention.
- xyzwlist[float], read-only
Quaternion as a list of float in the ‘xyzw’ convention.
- normfloat, read-only
The length (euclidean norm) of the quaternion.
- is_unitbool, read-only
True if the quaternion is unit-length. False otherwise.
Notes
The default convention to represent a quaternion
in this module is by four real values , , , . The first value is the scalar (real) part, and , , form the vector (complex, imaginary) part [1], so that:where
are basis components with following multiplication rules [2]:Quaternions are associative but not commutative.
Quaternion as rotation.
A rotation through an angle
around an axis defined by a euclidean unit vector can be represented as a quaternion:i.e.:
For a quaternion to represent a rotation or orientation, it must be unit-length. A quaternion representing a rotation
resulting from applying a rotation to a rotation , i.e.: , is also unit-length.References
Examples
>>> Q = Quaternion(1.0, 1.0, 1.0, 1.0).unitized() >>> R = Quaternion(0.0,-0.1, 0.2,-0.3).unitized() >>> P = R*Q >>> P.is_unit True
Methods
Makes the quaternion canonic.
Returns a quaternion in canonic form.
Conjugate the quaternion.
Returns a conjugate quaternion.
Computes the cosine of the angle between the two quaternions
Creates a quaternion object from a frame.
Create a Quaternion from a transformation matrix.
Create a Quaternion from a Rotatation.
Slerp: spherical interpolation of two quaternions.
Scales the quaternion to make it unit-length.
Returns a quaternion with a unit-length.
Inherited Methods
Converts the instance to a string.
Compute the axis-aligned bounding box of the geometry.
Compute the oriented bounding box of the geometry.
Make an independent copy of the data object.
Construct an object of this type from a JSON file.
Construct an object of this type from a JSON string.
Rotate the geometry.
Returns a rotated copy of this geometry.
Scale the geometry.
Returns a scaled copy of this geometry.
Compute a hash of the data for comparison during version control using the sha256 algorithm.
Convert an object to its native data representation and save it to a JSON file.
Convert an object to its native data representation and save it to a JSON string.
Transform the geometry.
Returns a transformed copy of this geometry.
Translate the geometry.
Returns a translated copy of this geometry.
Validate the data against the object's data schema.