# FreeBSD Manual Pages

QUATERNION(3) Library Functions Manual QUATERNION(3)NAMEqtom, mtoq, qadd, qsub, qneg, qmul, qdiv, qunit, qinv, qlen, slerp, qmid, qsqrt - Quaternion arithmeticSYNOPSIS#include<draw.h>#include<geometry.h>Quaternionqadd(Quaternionq,Quaternionr)Quaternionqsub(Quaternionq,Quaternionr)Quaternionqneg(Quaternionq)Quaternionqmul(Quaternionq,Quaternionr)Quaternionqdiv(Quaternionq,Quaternionr)Quaternionqinv(Quaternionq)doubleqlen(Quaternionp)Quaternionqunit(Quaternionq)voidqtom(Matrixm,Quaternionq)Quaternionmtoq(Matrixmat)Quaternionslerp(Quaternionq,Quaternionr,doublea)Quaternionqmid(Quaternionq,Quaternionr)Quaternionqsqrt(Quaternionq)DESCRIPTIONThe Quaternions are a non-commutative extension field of the Real num- bers, designed to do for rotations in 3-space what the complex numbers do for rotations in 2-space. Quaternions have a real componentrand an imaginary vector componentv=(i,j,k). Quaternions add componentwise and multiply according to the rule (r,v)(s,w)=(rs-v.w,rw+vs+vAw), where . andAare the ordinary vector dot and cross products. The mul- tiplicative inverse of a non-zero quaternion (r,v) is (r,-v)/(r2-v.v). The following routines do arithmetic on quaternions, represented as typedef struct Quaternion Quaternion; struct Quaternion{ double r, i, j, k; }; Name DescriptionqaddAdd two quaternions.qsubSubtract two quaternions.qnegNegate a quaternion.qmulMultiply two quaternions.qdivDivide two quaternions.qinvReturn the multiplicative inverse of a quaternion.qlenReturnsqrt(q.r*q.r+q.i*q.i+q.j*q.j+q.k*q.k), the length of a quaternion.qunitReturn a unit quaternion (length=1) with components proportional toq's. A rotation by angle_I,about axisA(whereAis a unit vector) can be represented by the unit quaternionq=(cos_I,/2,Asin_I,/2). The same rotation is represented by -q; a rotation by -_I,about -Ais the same as a rotation by_I,aboutA. The quaternionqtransforms points by (0,x',y',z') =q-1(0,x,y,z)q. Quaternion multiplication composes rota- tions. The orientation of an object in 3-space can be represented by a quaternion giving its rotation relative to some `standard' orientation. The following routines operate on rotations or orientations represented as unit quaternions:mtoqConvert a rotation matrix (see to a unit quaternion.qtomConvert a unit quaternion to a rotation matrix.slerpSpherical lerp. Interpolate between two orientations. The ro- tation that carriesqtorisq-1r, soslerp(q,r,t)isq(q-1r)t.qmidslerp(q,r,.5)qsqrtThe square root ofq. This is just a rotation about the same axis by half the angle.SOURCE/src/libgeometry/quaternion.cSEE ALSOBUGSTo avoid name conflicts with NetBSD,qdivis a preprocessor macro de- fined asp9qdiv; see QUATERNION(3)

NAME | SYNOPSIS | DESCRIPTION | SOURCE | SEE ALSO | BUGSNAME | SYNOPSIS | DESCRIPTION | SOURCE | SEE ALSO | BUGS

Want to link to this manual page? Use this URL:

<https://www.freebsd.org/cgi/man.cgi?query=quaternion&sektion=3&manpath=FreeBSD+12.2-RELEASE+and+Ports>