splines.quaternion§

Quaternions and unit-quaternion splines.

Functions

canonicalized(quaternions)

Iterator adapter to ensure minimal angles between quaternions.

slerp(one, two, t)

Spherical Linear intERPolation.

Classes

BarryGoldman(quaternions[, grid, alpha])

Rotation spline using Barry--Goldman algorithm.

CatmullRom(quaternions[, grid, alpha, ...])

Catmull--Rom-like rotation spline.

DeCasteljau(segments[, grid])

Spline using De Casteljau's algorithm with slerp().

KochanekBartels(quaternions[, grid, tcb, ...])

Kochanek--Bartels-like rotation spline.

PiecewiseSlerp(quaternions, *[, grid, closed])

Piecewise Slerp.

Quaternion(scalar, vector)

A very simple quaternion class.

UnitQuaternion()

Unit quaternion.

class splines.quaternion.Quaternion(scalar, vector)[source]§

Bases: object

A very simple quaternion class.

This is the base class for the more relevant UnitQuaternion class.

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.

conjugate()[source]§

Return quaternion with same scalar part, negated vector part.

normalized()[source]§

Return quaternion with same 4D direction but unit norm.

dot(other)[source]§

Dot product of two quaternions.

This is the 4-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.

property xyzw§

Components of the quaternion, scalar last.

property wxyz§

Components of the quaternion, scalar first.

class splines.quaternion.UnitQuaternion[source]§

Bases: splines.quaternion.Quaternion

Unit quaternion.

See the section about unit quaternions.

classmethod from_axis_angle(axis, angle)[source]§

Create a unit quaternion from a rotation axis and angle.

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.

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\).

Returns

Corresponding 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).

rotate_vector(v)[source]§

Apply rotation to a 3D vector.

Parameters

v (3-tuple) – A vector in \(R^3\).

Returns

The rotated vector.

splines.quaternion.slerp(one, two, t)[source]§

Spherical Linear intERPolation.

See Spherical Linear Interpolation (Slerp).

Parameters
  • one – Start quaternion.

  • two – End quaternion.

  • t – Parameter value(s) between 0 and 1.

splines.quaternion.canonicalized(quaternions)[source]§

Iterator adapter to ensure minimal angles between quaternions.

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.

evaluate(t, n=0)[source]§
class splines.quaternion.DeCasteljau(segments, grid=None)[source]§

Bases: object

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, …).

evaluate(t, n=0)[source]§

Get value or angular velocity at given parameter value(s).

Parameters
  • t – Parameter value(s).

  • n ({0, 1}, optional) – Use 0 for calculating the value (a quaternion), 1 for the angular velocity (a 3-element vector).

class splines.quaternion.KochanekBartels(quaternions, grid=None, *, tcb=(0, 0, 0), alpha=None, endconditions='natural')[source]§

Bases: splines.quaternion.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) – TODO

  • endconditions (optional) –

    Start/end conditions. Can be 'closed', 'natural' or pair of tangent vectors (a.k.a. “clamped”).

    TODO: clamped

    If 'closed', the first rotation is re-used as last rotation and an additional grid time has to be specified.

class splines.quaternion.CatmullRom(quaternions, grid=None, *, alpha=None, endconditions='natural')[source]§

Bases: splines.quaternion.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.

class splines.quaternion.BarryGoldman(quaternions, grid=None, *, alpha=None)[source]§

Bases: object

Rotation spline using Barry–Goldman algorithm.

Always closed (for now).

evaluate(t)[source]§