splines.quaternion#
Quaternions and unit-quaternion splines.
- class splines.quaternion.Quaternion(scalar, vector)[source]#
Bases:
object
A very simple quaternion class.
This is the base class for the more relevant class
UnitQuaternion
.See the notebook about quaternions.
- property scalar#
The scalar part (a.k.a. real part) of the quaternion.
- property vector#
The vector part (a.k.a. imaginary part) of the quaternion.
- dot(other)[source]#
Dot product of two quaternions.
This is the four-dimensional dot product, yielding a scalar result. This operation is commutative.
Note that this is different from the quaternion multiplication (
q1 * q2
), which produces another quaternion (and is noncommutative).
- property norm#
Length of the quaternion in 4D space.
- class splines.quaternion.UnitQuaternion[source]#
Bases:
Quaternion
Unit quaternion.
See the section about unit quaternions.
- classmethod from_axis_angle(axis, angle)[source]#
Create a unit quaternion from a rotation
axis
andangle
.- Parameters:
axis – Three-component rotation axis. This will be normalized.
angle – Rotation angle in radians.
- classmethod from_unit_xyzw(xyzw)[source]#
Create a unit quaternion from another unit quaternion.
- Parameters:
xyzw – Components of a unit quaternion (
scalar
last). This will not be normalized, it must already have unit length.
- inverse()#
Multiplicative inverse.
For unit quaternions, this is the same as
conjugate()
.
- classmethod exp_map(value)[source]#
Exponential map from \(R^3\) to unit quaternions.
The exponential map operation transforms a three-dimensional vector that’s a member of the tangent space at the identity quaternion into a unit quaternion.
This is the inverse operation to
log_map()
.- Parameters:
value (3-tuple) – Element of the tangent space at the quaternion identity.
- log_map()[source]#
Logarithmic map from unit quaternions to \(R^3\).
The logarithmic map operation transforms a unit quaternion into a three-dimensional vector that’s a member of the tangent space at the identity quaternion.
This is the inverse operation to
exp_map()
.- Returns:
Corresponding three-element vector in the tangent space at the quaternion identity.
- property axis#
The (normalized) rotation axis.
- property angle#
The rotation angle in radians.
- rotation_to(other)[source]#
Rotation required to rotate self into other.
See Relative Rotation (Global Frame of Reference).
- Parameters:
other (
UnitQuaternion
) – Target rotation.- Returns:
Relative rotation – as
UnitQuaternion
.
- splines.quaternion.slerp(one, two, t)[source]#
Spherical Linear intERPolation.
See Spherical Linear Interpolation (Slerp).
- Parameters:
one (
UnitQuaternion
) – Start rotation.two (
UnitQuaternion
) – End rotation.t – Parameter value(s) between 0 and 1.
- splines.quaternion.canonicalized(quaternions)[source]#
Iterator adapter to ensure minimal angles between quaternions.
See Canonicalization.
- class splines.quaternion.PiecewiseSlerp(quaternions, *, grid=None, closed=False)[source]#
Bases:
object
Piecewise Slerp.
See Piecewise Slerp.
- Parameters:
quaternions – Sequence of rotations to be interpolated. The quaternions will be
canonicalized()
.grid (optional) – Sequence of parameter values. Must be strictly increasing. Must have the same length as quaternions, except when closed is
True
, where it must be one element longer. If not specified, a uniform grid is used (0, 1, 2, 3, …).closed (optional) – If
True
, the first quaternion is repeated at the end.
- class splines.quaternion.DeCasteljau(segments, grid=None)[source]#
Bases:
object
Rotation spline using De Casteljau’s algorithm with
slerp()
.See the corresponding notebook for details.
- Parameters:
segments – Sequence of segments, each one consisting of multiple control quaternions. Different segments can have different numbers of control points.
grid (optional) – Sequence of parameter values corresponding to segment boundaries. Must be strictly increasing. If not specified, a uniform grid is used (0, 1, 2, 3, …).
- class splines.quaternion.KochanekBartels(quaternions, grid=None, *, tcb=(0, 0, 0), alpha=None, endconditions='natural')[source]#
Bases:
DeCasteljau
Kochanek–Bartels-like rotation spline.
See the corresponding notebook for details.
- Parameters:
quaternions – Sequence of rotations to be interpolated. The quaternions will be
canonicalized()
.grid (optional) – Sequence of parameter values. Must be strictly increasing. If not specified, a uniform grid is used (0, 1, 2, 3, …).
tcb (optional) – Sequence of tension, continuity and bias triples. TCB values can only be given for the interior quaternions. If only two quaternions are given, TCB values are ignored.
alpha (optional) – See Parameterized Parameterization.
endconditions (optional) – Start/end conditions. Can be
'closed'
or'natural'
. If'closed'
, the first rotation is re-used as last rotation and an additional grid value has to be specified.
- class splines.quaternion.CatmullRom(quaternions, grid=None, *, alpha=None, endconditions='natural')[source]#
Bases:
KochanekBartels
Catmull–Rom-like rotation spline.
This is just
KochanekBartels
without TCB values.See Uniform Catmull--Rom-Like Quaternion Splines and Non-Uniform Catmull--Rom-Like Rotation Splines.