Quaternion
- class compas.geometry.Quaternion(w, x, y, z, **kwargs)[source]
Bases:
Primitive
A quaternion is defined by 4 components, X, Y, Z, and W.
- Parameters
w (float) – The scalar (real) part of a quaternion.
x, y, z (float) – Components of the vector (complex, imaginary) part of a quaternion.
- Attributes
w (float) – The W component of the quaternion.
x (float) – The X component of the quaternion.
y (float) – The Y component of the quaternion.
z (float) – The Z component of the quaternion.
wxyz (list[float], read-only) – Quaternion as a list of float in the ‘wxyz’ convention.
xyzw (list[float], read-only) – Quaternion as a list of float in the ‘xyzw’ convention.
norm (float, read-only) – The length (euclidean norm) of the quaternion.
is_unit (bool, read-only) – True if the quaternion is unit-length. False otherwise.
Notes
The default convention to represent a quaternion q in this module is by four real values w, x, y, z. The first value w is the scalar (real) part, and x, y, z form the vector (complex, imaginary) part 1, so that:
q=w+xi+yj+zkwhere i,j,k are basis components with following multiplication rules 2:
ii=jj=kk=ijk=−1ij=k,ji=−kjk=i,kj=−iki=j,ik=−jQuaternions are associative but not commutative.
Quaternion as rotation.
A rotation through an angle θ around an axis defined by a euclidean unit vector u=uxi+uyj+uzk can be represented as a quaternion:
q=cos(θ2)+sin(θ2)[uxi+uyj+uzk]i.e.:
w=cos(θ2)x=sin(θ2)uxy=sin(θ2)uyz=sin(θ2)uzFor a quaternion to represent a rotation or orientation, it must be unit-length. A quaternion representing a rotation p resulting from applying a rotation r to a rotation q, i.e.: p=rq, 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.
Construct a quaternion from a data dict.
Creates a quaternion object from a frame.
Create a Quaternion from a transformation matrix.
Create a Quaternion from a Rotatation.
Scales the quaternion to make it unit-length.
Returns a quaternion with a unit-length.
Inherited Methods
Converts the instance to a string.
Make an independent copy of the data object.
Construct an object from serialized data contained in a JSON file.
Construct an object from serialized data contained in a JSON string.
Compute a hash of the data for comparison during version control using the sha256 algorithm.
Convert an object to its native data representation.
Serialize the data representation of an object to a JSON file.
Serialize the data representation of an object to a JSON string.
Transform the geometry.
Returns a transformed copy of this geometry.
Validate the object's data against its data schema.
Validate the object's data against its json schema.