Quaternion math routines. More...

#include "common.h"
#include <stdio.h>
#include <math.h>
#include "vmath.h"
#include "bn/qmath.h"
Include dependency graph for qmath.c:

Go to the source code of this file.


#define XX   0
#define YY   5
#define ZZ   10
#define MMM(a, b)   mat[4*(a)+(b)]


void quat_mat2quat (register fastf_t *quat, register const fastf_t *mat)
void quat_quat2mat (register fastf_t *mat, register const fastf_t *quat)
double quat_distance (const fastf_t *q1, const fastf_t *q2)
void quat_double (fastf_t *qout, const fastf_t *q1, const fastf_t *q2)
void quat_bisect (fastf_t *qout, const fastf_t *q1, const fastf_t *q2)
void quat_slerp (fastf_t *qout, const fastf_t *q1, const fastf_t *q2, double f)
void quat_sberp (fastf_t *qout, const fastf_t *q1, const fastf_t *qa, const fastf_t *qb, const fastf_t *q2, double f)
void quat_make_nearest (fastf_t *q1, const fastf_t *q2)
void quat_print (const char *title, const fastf_t *quat)
void quat_exp (fastf_t *out, const fastf_t *in)
void quat_log (fastf_t *out, const fastf_t *in)

Detailed Description

Quaternion math routines.

Unit Quaternions: Q = [ r, a ] where r = cos(theta/2) = rotation amount |a| = sin(theta/2) = rotation axis

If a = 0 we have the reals; if one coord is zero we have complex numbers (2D rotations).

[r, a][s, b] = [rs - a.b, rb + sa + axb]


[r, a] = (r - a) / (r^2 + a.a)

Powers of quaternions yield incremental rotations, e.g. Q^3 is rotated three times as far as Q.

Some operations on quaternions: -1 [0, P'] = Q [0, P]Q Rotate a point P by quaternion Q -1 a slerp(Q, R, a) = Q(Q R) Spherical linear interp: 0 < a < 1

bisect(P, Q) = (P + Q) / |P + Q| Great circle bisector

Additions inspired by "Quaternion Calculus For Animation" by Ken Shoemake, SIGGRAPH '89 course notes for "Math for SIGGRAPH", May 1989.

Definition in file qmath.c.

Macro Definition Documentation

#define XX   0

Referenced by quat_mat2quat().

#define YY   5

Referenced by quat_mat2quat().

#define ZZ   10

Referenced by quat_mat2quat().

#define MMM (   a,
)    mat[4*(a)+(b)]

Referenced by quat_mat2quat().