template<class T>
Magnum::Math::CubicHermite class

Cubic Hermite spline point.

Represents a point on a cubic Hermite spline.

Unlike Bezier, which describes a curve segment, this structure describes a spline point $ \boldsymbol{p} $ , with in-tangent $ \boldsymbol{m} $ and out-tangent $ \boldsymbol{n} $ . This form is more suitable for animation keyframe representation. The structure assumes the in/out tangents to be in their final form, i.e. already normalized by length of their adjacent segments.

Cubic Hermite splines are fully interchangeable with cubic Bézier curves, use fromBezier() and Bezier::fromCubicHermite() for the conversion.

Public types

using Type = T
Underlying data type.

Public static functions

template<UnsignedInt dimensions, class U>
static auto fromBezier(const CubicBezier<dimensions, U>& a, const CubicBezier<dimensions, U>& b) -> CubicHermite<T>
Create cubic Hermite spline point from adjacent Bézier curve segments.

Constructors, destructors, conversion operators

CubicHermite() constexpr noexcept
Default constructor.
CubicHermite(ZeroInitT) explicit constexpr noexcept
Default constructor.
template<class U = T, class = typename std::enable_if<std::is_constructible<U, IdentityInitT>::value>::type>
CubicHermite(IdentityInitT) explicit constexpr noexcept
Identity constructor.
CubicHermite(Magnum::NoInitT) explicit noexcept
Construct cubic Hermite spline point without initializing its contents.
CubicHermite(const T& inTangent, const T& point, const T& outTangent) constexpr noexcept
Construct cubic Hermite spline point with given control points.
template<class U>
CubicHermite(const CubicHermite<U>& other) explicit constexpr noexcept
Construct cubic Hermite spline point from another of different type.

Public functions

auto data() -> T*
Raw data.
auto data() const -> const T*
auto operator==(const CubicHermite<T>& other) const -> bool
Equality comparison.
auto operator!=(const CubicHermite<T>& other) const -> bool
Non-equality comparison.
auto inTangent() -> T&
In-tangent $ \boldsymbol{m} $ .
auto inTangent() const -> const T& constexpr
auto point() -> T&
Point $ \boldsymbol{p} $ .
auto point() const -> const T& constexpr
auto outTangent() -> T&
Out-tangent $ \boldsymbol{n} $ .
auto outTangent() const -> const T& constexpr

Function documentation

template<class T> template<UnsignedInt dimensions, class U>
static CubicHermite<T> Magnum::Math::CubicHermite<T>::fromBezier(const CubicBezier<dimensions, U>& a, const CubicBezier<dimensions, U>& b)

Create cubic Hermite spline point from adjacent Bézier curve segments.

Given two adjacent cubic Bézier curve segments defined by points $ \boldsymbol{a}_i $ and $ \boldsymbol{b}_i $ , $ i \in \{ 0, 1, 2, 3 \} $ , the corresponding cubic Hermite spline point $ \boldsymbol{p} $ , in-tangent $ \boldsymbol{m} $ and out-tangent $ \boldsymbol{n} $ is defined as:

\[ \begin{array}{rcl} \boldsymbol{m} & = & 3 (\boldsymbol{a}_3 - \boldsymbol{a}_2) = 3 (\boldsymbol{b}_0 - \boldsymbol{a}_2) \\ \boldsymbol{p} & = & \boldsymbol{a}_3 = \boldsymbol{b}_0 \\ \boldsymbol{n} & = & 3 (\boldsymbol{b}_1 - \boldsymbol{a}_3) = 3 (\boldsymbol{b}_1 - \boldsymbol{b}_0) \end{array} \]

Expects that the two segments are adjacent (i.e., the endpoint of first segment is the start point of the second). If you need to create a cubic Hermite spline point that's at the beginning or at the end of a curve, simply pass a dummy Bézier segment that satisfies this constraint as the other parameter:

CubicBezier2D segment;
auto startPoint = CubicHermite2D::fromBezier(
    {Vector2{}, Vector2{}, Vector2{}, segment[3]}, segment);
auto endPoint = CubicHermite2D::fromBezier(segment,
    {segment[0], Vector2{}, Vector2{}, Vector2{}});

Enabled only on vector underlying types. See Bezier::fromCubicHermite() for the inverse operation.

template<class T>
Magnum::Math::CubicHermite<T>::CubicHermite() constexpr noexcept

Default constructor.

Equivalent to CubicHermite(ZeroInitT) for vector types and to CubicHermite(IdentityInitT) for complex and quaternion types.

template<class T>
Magnum::Math::CubicHermite<T>::CubicHermite(ZeroInitT) explicit constexpr noexcept

Default constructor.

Construct cubic Hermite spline point with all control points being zero.

template<class T> template<class U = T, class = typename std::enable_if<std::is_constructible<U, IdentityInitT>::value>::type>
Magnum::Math::CubicHermite<T>::CubicHermite(IdentityInitT) explicit constexpr noexcept

Identity constructor.

The point() is constructed as identity in order to have interpolation working correctly; inTangent() and outTangent() is constructed as zero. Enabled only for complex and quaternion types.

template<class T>
Magnum::Math::CubicHermite<T>::CubicHermite(const T& inTangent, const T& point, const T& outTangent) constexpr noexcept

Construct cubic Hermite spline point with given control points.

Parameters
inTangent In-tangent $ \boldsymbol{m} $
point Point $ \boldsymbol{p} $
outTangent Out-tangent $ \boldsymbol{n} $

template<class T> template<class U>
Magnum::Math::CubicHermite<T>::CubicHermite(const CubicHermite<U>& other) explicit constexpr noexcept

Construct cubic Hermite spline point from another of different type.

Performs only default casting on the values, no rounding or anything else.

template<class T>
T* Magnum::Math::CubicHermite<T>::data()

Raw data.

Contrary to what Doxygen shows, returns reference to an one-dimensional fixed-size array of three elements, i.e. T(&)[3].

template<class T>
const T* Magnum::Math::CubicHermite<T>::data() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
const T& Magnum::Math::CubicHermite<T>::inTangent() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
const T& Magnum::Math::CubicHermite<T>::point() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
const T& Magnum::Math::CubicHermite<T>::outTangent() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T> template<class T>
Debug& operator<<(Debug& debug, const CubicHermite<T>& value)

Debug output operator.

template<class T> template<class T, class U>
T select(const CubicHermite<T>& a, const CubicHermite<T>& b, U t)

Constant interpolation of two cubic Hermite spline points.

Parameters
a First spline point
b Second spline point
t Interpolation phase (from range $ [0; 1] $ )

Given segment points $ \boldsymbol{p}_i $ , in-tangents $ \boldsymbol{m}_i $ and out-tangents $ \boldsymbol{n}_i $ , the interpolated value $ \boldsymbol{p} $ at phase $ t $ is:

\[ \boldsymbol{p}(t) = \begin{cases} \boldsymbol{p}_a, & t < 1 \\ \boldsymbol{p}_b, & t \ge 1 \end{cases} \]

Equivalent to calling select(const T&, const T&, U) on CubicHermite::point() extracted from both a and b.

template<class T> template<class T, class U>
T lerp(const CubicHermite<T>& a, const CubicHermite<T>& b, U t)

Linear interpolation of two cubic Hermite points.

Parameters
a First spline point
b Second spline point
t Interpolation phase (from range $ [0; 1] $ )

Given segment points $ \boldsymbol{p}_i $ , in-tangents $ \boldsymbol{m}_i $ and out-tangents $ \boldsymbol{n}_i $ , the interpolated value $ \boldsymbol{p} $ at phase $ t $ is:

\[ \boldsymbol{p}(t) = (1 - t) \boldsymbol{p}_a + t \boldsymbol{p}_b \]

Equivalent to calling lerp(const T&, const T&, U) on CubicHermite::point() extracted from both a and b.

template<class T> template<class T>
Complex<T> lerp(const CubicHermiteComplex<T>& a, const CubicHermiteComplex<T>& b, T t)

Linear interpolation of two cubic Hermite complex numbers.

Equivalent to calling lerp(const Complex<T>&, const Complex<T>&, T) on CubicHermite::point() extracted from a and b. Compared to lerp(const CubicHermite<T>&, const CubicHermite<T>&, U) this adds a normalization step after. Expects that CubicHermite::point() is a normalized complex number in both a and b.

template<class T> template<class T>
Quaternion<T> lerp(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t)

Linear interpolation of two cubic Hermite quaternions.

Equivalent to calling lerp(const Quaternion<T>&, const Quaternion<T>&, T) on CubicHermite::point() extracted from a and b. Compared to lerp(const CubicHermite<T>&, const CubicHermite<T>&, U) this adds a normalization step after. Expects that CubicHermite::point() is a normalized quaternion in both a and b.

template<class T> template<class T>
Quaternion<T> lerpShortestPath(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t)

Linear shortest-path interpolation of two cubic Hermite quaternions.

Equivalent to calling lerpShortestPath(const Quaternion<T>&, const Quaternion<T>&, T) on CubicHermite::point() extracted from a and b. Expects that CubicHermite::point() is a normalized quaternion in both a and b.

Note that rotations interpolated with this function may go along a completely different path compared to splerp(const CubicHermiteQuaternion<T>&, const CubicHermiteQuaternion<T>&, T). Use lerp(const CubicHermiteQuaternion<T>&, const CubicHermiteQuaternion<T>&, T) for behavior that is consistent with spline interpolation.

template<class T> template<class T>
Quaternion<T> slerp(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t)

Spherical linear interpolation of two cubic Hermite quaternions.

Equivalent to calling slerp(const Quaternion<T>&, const Quaternion<T>&, T) on CubicHermite::point() extracted from a and b. Expects that CubicHermite::point() is a normalized quaternion in both a and b.

template<class T> template<class T>
Quaternion<T> slerpShortestPath(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t)

Spherical linear shortest-path interpolation of two cubic Hermite quaternions.

Equivalent to calling slerpShortestPath(const Quaternion<T>&, const Quaternion<T>&, T) on CubicHermite::point() extracted from a and b. Expects that CubicHermite::point() is a normalized quaternion in both a and b.

Note that rotations interpolated with this function may go along a completely different path compared to splerp(const CubicHermiteQuaternion<T>&, const CubicHermiteQuaternion<T>&, T). Use slerp(const CubicHermiteQuaternion<T>&, const CubicHermiteQuaternion<T>&, T) for spherical linear interpolation with behavior that is consistent with spline interpolation.

template<class T> template<class T, class U>
T splerp(const CubicHermite<T>& a, const CubicHermite<T>& b, U t)

Spline interpolation of two cubic Hermite points.

Parameters
a First spline point
b Second spline point
t Interpolation phase

Given segment points $ \boldsymbol{p}_i $ , in-tangents $ \boldsymbol{m}_i $ and out-tangents $ \boldsymbol{n}_i $ , the interpolated value $ \boldsymbol{p} $ at phase $ t $ is:

\[ \boldsymbol{p}(t) = (2 t^3 - 3 t^2 + 1) \boldsymbol{p}_a + (t^3 - 2 t^2 + t) \boldsymbol{n}_a + (-2 t^3 + 3 t^2) \boldsymbol{p}_b + (t^3 - t^2)\boldsymbol{m}_b \]

template<class T> template<class T>
Complex<T> splerp(const CubicHermiteComplex<T>& a, const CubicHermiteComplex<T>& b, T t)

Spline interpolation of two cubic Hermite complex numbers.

Unlike splerp(const CubicHermite<T>&, const CubicHermite<T>&, U) this adds a normalization step after. Given segment points $ \boldsymbol{p}_i $ , in-tangents $ \boldsymbol{m}_i $ and out-tangents $ \boldsymbol{n}_i $ , the interpolated value $ \boldsymbol{p} $ at phase $ t $ is:

\[ \begin{array}{rcl} \boldsymbol{p'}(t) & = & (2 t^3 - 3 t^2 + 1) \boldsymbol{p}_a + (t^3 - 2 t^2 + t) \boldsymbol{n}_a + (-2 t^3 + 3 t^2) \boldsymbol{p}_b + (t^3 - t^2)\boldsymbol{m}_b \\ \boldsymbol{p}(t) & = & \cfrac{\boldsymbol{p'}(t)}{|\boldsymbol{p'}(t)|} \end{array} \]

Expects that CubicHermite::point() is a normalized complex number in both a and b.

template<class T> template<class T>
Quaternion<T> splerp(const CubicHermiteQuaternion<T>& a, const CubicHermiteQuaternion<T>& b, T t)

Spline interpolation of two cubic Hermite quaternions.

Unlike splerp(const CubicHermite<T>&, const CubicHermite<T>&, U) this adds a normalization step after. Given segment points $ \boldsymbol{p}_i $ , in-tangents $ \boldsymbol{m}_i $ and out-tangents $ \boldsymbol{n}_i $ , the interpolated value $ \boldsymbol{p} $ at phase $ t $ is:

\[ \begin{array}{rcl} \boldsymbol{p'}(t) & = & (2 t^3 - 3 t^2 + 1) \boldsymbol{p}_a + (t^3 - 2 t^2 + t) \boldsymbol{n}_a + (-2 t^3 + 3 t^2) \boldsymbol{p}_b + (t^3 - t^2)\boldsymbol{m}_b \\ \boldsymbol{p}(t) & = & \cfrac{\boldsymbol{p'}(t)}{|\boldsymbol{p'}(t)|} \end{array} \]

Expects that CubicHermite::point() is a normalized quaternion in both a and b.