Unit CastleQuaternions

DescriptionUsesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

Quaternions (in particular using them to express 3D rotations).

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
Object TQuaternion  

Functions and Procedures

function QuatFromAxisAngle(const Axis: TVector3Single; const AngleRad: Single; const NormalizeAxis: boolean = false): TQuaternion;
function QuatFromAxisAngle(const AxisAngle: TVector4Single; const NormalizeAxis: boolean = false): TQuaternion;
operator * (const Q1, Q2: TQuaternion): TQuaternion;
function SLerp(const A: Single; const Q1, Q2: TQuaternion): TQuaternion;
function SLerp(const A: Single; const Rot1, Rot2: TVector4Single): TVector4Single;
function NLerp(const A: Single; const Q1, Q2: TQuaternion; const ForceShortestPath: boolean = true): TQuaternion;
function NLerp(const A: Single; const Rot1, Rot2: TVector4Single; const ForceShortestPath: boolean = true): TVector4Single;

Constants

QuatIdentityRot: TQuaternion = (Data: (Vector: (0, 0, 0); Real: 1));

Description

Functions and Procedures

function QuatFromAxisAngle(const Axis: TVector3Single; const AngleRad: Single; const NormalizeAxis: boolean = false): TQuaternion;

Calculate unit quaternion representing rotation around Axis by AngleRad angle (in radians).

Axis must be normalized, or you have to pass NormalizeAxis = true (then we'll normalize it ourselves inside). Otherwise you will get non-normalized quaternion that doesn't represent rotation, and is usually useless for us.

function QuatFromAxisAngle(const AxisAngle: TVector4Single; const NormalizeAxis: boolean = false): TQuaternion;
 
operator * (const Q1, Q2: TQuaternion): TQuaternion;

Multiply two quaternions.

Geometric interpretation: If these are unit quaternions representing rotations, multiplying them calculates one rotation that has the same effect as rotating by Q2 and then by Q1.

Normal of result is equal to norm of Q1 * norm of Q2 (in particular, multiplying unit quaternions (used for rotations) yields another unit quaternion for sure).

function SLerp(const A: Single; const Q1, Q2: TQuaternion): TQuaternion;

Interpolate between two rotations, along the shortest path on the unit sphere, with constant speed.

The overloaded version that works with TVector4Single takes a rotation (not a quaternion) expressed as an axis (first 3 elements) and angle (in radians, 4th element). Axis does not have to be normalized (we'll normalize it). This is nice e.g. to interpolate VRML/X3D rotations.

function SLerp(const A: Single; const Rot1, Rot2: TVector4Single): TVector4Single;
 
function NLerp(const A: Single; const Q1, Q2: TQuaternion; const ForceShortestPath: boolean = true): TQuaternion;

Interpolate between two rotations, along the straightest path on the unit sphere.

This is faster than SLerp, but does not guarantee the interpolated result travels with constant speed. Often it's not a noticeable / important problem (see http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/)

When ForceShortestPath = False, this doesn't guarantee choosing the shortest path. Although it goes through the straightest path, there are two such paths, it may go through the shorter or longer one. Use ForceShortestPath = True if you want to interpolate through the shortest.

The overloaded version that works with TVector4Single takes a rotation (not a quaternion) expressed as an axis (first 3 elements) and angle (in radians, 4th element). Axis does not have to be normalized (we'll normalize it). This is nice e.g. to interpolate VRML/X3D rotations.

function NLerp(const A: Single; const Rot1, Rot2: TVector4Single; const ForceShortestPath: boolean = true): TVector4Single;
 

Constants

QuatIdentityRot: TQuaternion = (Data: (Vector: (0, 0, 0); Real: 1));
 

Generated by PasDoc 0.13.0 on 2013-08-17 21:27:13