9. Math classes and conventions in AGX

There are numerous classes related to math operations and conversions in AGX. This chapter tries to describe the conventions used for these classes. agx::Real is the data type used for all floating point operations in AGX. Common for all rotations is that radians are used for all methods. agx:degreesToRadians() and agx::radiansToDegrees() can be used to convert between degrees and radians. The header file <agx/Math.h> contains utility methods related to math operations such as:

absolute( a )

Return absolute value of argument.

equivalent( a, b )

Return true if the two arguments are equal.

equalsZero( a )

Return true if argument is equal to zero.

minimum(a, b), maximum(a, b)

Return minimum or maximum of the two arguments.

clamp( a, min, max )

Return clamped argument a below min and max.

square( a )

Return square of a.

signedSqare( a )

Return squared argument a.

clampAbove( a, minimum )

Return clamped argument above minimum.

clampBelow( a, maximum )

Return clamped argument below maximum.

sign( a )

Return sign of argument.

9.1. Small vectors

Vec2, Vec3 and Vec4 are vectors for storing points and vectors in 2, 3 and 4 dimensions. Each method has methods for dot product, cross products and overloaded operators for +,-, scalar operations such as *, / etc.

9.2. agx::AffineMatrix4x4

This is a 4x4 matrix that can store a concatenated rigid rotation and translation. It is stored in row order:

\(R_x0\)

\(R_x1\)

\(R_x2\)

0

\(R_y0\)

\(R_y1\)

\(R_y2\)

0

\(R_z0\)

\(R_z1\)

\(R_z2\)

0

\(T_x\)

\(T_y\)

\(T_z\)

1

A vector-matrix multiplication is performed as: vM= M*v and its transpose is calculated as vM’=v*M.

The AffineMatrix4x4 is always considered to be orthonormalized, which means that the call to AffineMatrix4x4::inverse() will perform a transpose, as the transpose of a orthonormalized matrix is the same as the full inverse of the same. An AffineMatrix4x4 should never contain scaling or shearing, only rigid transformations.

9.3. agx::OrthoMatrix3x3

This is a rotation matrix with the same conventions and methods (except everything related to translation) as the AffineMatrix4x4.

\(R_x0\)

\(R_x1\)

\(R_x2\)

\(R_y0\)

\(R_y1\)

\(R_y2\)

\(R_z0\)

\(R_z1\)

\(R_z2\)

9.4. agx::Quat

Quaternion is a compressed representation of a rotation based on a vector and a scalar: q = [<x, y, z>, w], where <x, y, z> is a three dimensional vector and w is a scalar. Quaternions can be interpolated using linear interpolation: agx::lerp(t, q1, q2) or spherical linear interpolation: Quat::slerp(t, q1, q2);

9.5. agx::EulerAngles

EulerAngles is a more intuitive way of specifying rotations, as rotations can be specified per axis. There are 24 different conventions for representing rotations in Euler. This class can convert back and forth between all representations. Most classes can convert between the different rotation specifications.