# quatinterp

Quaternion interpolation between two quaternions

## Description

example

qi=quatinterp(p,q,f,method) calculates the quaternion interpolation between two normalized quaternions p and q by interval fraction f.

p and q are the two extremes between which the function calculates the quaternion.

Aerospace Toolbox uses quaternions that are defined using the scalar-first convention.

## Examples

collapse all

Use interpolation to calculate quaternion between two quaternions p=[1.0 0 1.0 0] and q=[-1.0 0 1.0 0] using the SLERP method. This example uses the quatnormalize function to first-normalize the two quaternions to pn and qn.

pn = quatnormalize([1.0 0 1.0 0])
qn = quatnormalize([-1.0 0 1.0 0])
qi = quatinterp(pn,qn,0.5,'slerp')
pn =

0.7071         0    0.7071         0

qn =

-0.7071         0    0.7071         0

qi =

0     0     1     0

## Input Arguments

collapse all

First normalized quaternion for which to calculate the interpolation, specified as an M-by-4 matrix containing M quaternions. This quaternion must be a normalized quaternion.

Data Types: double

Second normalized quaternion for which to calculate the interpolation, specified as an M-by-4 matrix containing M quaternions. This quaternion must be a normalized quaternion.

Data Types: double

Interval fraction by which to calculate the quaternion interpolation, specified as an M-by-1 matrix containing M fractions (scalar). f varies between 0 and 1. It represents the intermediate rotation of the quaternion to be calculated.

qi=(qp,qn,qf), where:

• If f equals 0, qi equals qp.

• If f is between 0 and 1, qi equals method.

• If f equals 1, qi equals qn.

Data Types: double

Quaternion interpolation method to calculate the quaternion interpolation. These methods have different rotational velocities, depending on the interval fraction. For more information on interval fractions, see [1].

• slerp

Quaternion slerp. Spherical linear quaternion interpolation method. This method is most accurate, but also most computation intense.

$Slerp\left(p,q,h\right)=p{\left({p}^{*}q\right)}^{h}$ with $h\in \left[0,1\right].$

• lerp

Quaternion lerp. Linear quaternion interpolation method. This method is the quickest, but is also least accurate. The method does not always generate normalized output.

$LERP\left(p,q,h\right)=p\left(1-h\right)+qh$ with $h\in \left[0,1\right].$

• nlerp

Normalized quaternion linear interpolation method.

With $r=LERP\left(p,q,h\right),$ $NLERP\left(p,q,h\right)=\frac{r}{|r|}.$

Data Types: char

## Output Arguments

collapse all

Interpolation of quaternion.

## References

[1] Dam, Erik B., Martin Koch, Martin Lillholm. "Quaternions, Interpolation, and Animation." University of Copenhagen, København, Denmark, 1998.