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.

property scalar§
property vector§
conjugate()[source]§
normalize()[source]§
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 non-commutative).

property norm§
property xyzw§
property wxyz§
class splines.quaternion.UnitQuaternion[source]§

Bases: splines.quaternion.Quaternion

Unit quaternion.

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 quaternions.

This is the inverse operation to log_map().

Parameters
  • value – Element of the tangent space at the quaternion identity.

  • type – 3-tuple

Returns

Corresponding unit quaternion.

log_map()[source]§

Logarithmic map from quaternions to \(R^3\).

Returns

Corresponding vector in the tangent space at the quaternion identity.

property axis§
property angle§
rotation_to(other)[source]§

Rotation required to rotate self into other.

See Relative Rotation (Global Frame of Reference).

rotate_vector(v)[source]§
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.

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.

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]§