Vector Math

Vector Math functions.

Point3

3-tuple

A 3-tuple (with 4-th element always set to 1)

EXAMPLES

dmVMath::Point3 p = dmVMath::Point3(x, y, z); // Create new point
float length_squared = p.getX() * p.getX() + p.getY() * p.getY() + p.getZ() * p.getZ();


Vector3

3-tuple

A 3-tuple (with 4-th element always set to 0)

EXAMPLES

dmVMath::Vector3 p = dmVMath::Vector3(x, y, z); // Create new vector
float length_squared = p.getX() * p.getX() + p.getY() * p.getY() + p.getZ() * p.getZ();


Vector4

4-tuple

A 4-tuple

EXAMPLES

dmVMath::Vector4 p = dmVMath::Vector4(x, y, z, w); // Create new vector
float length_squared = p.getX() * p.getX() + p.getY() * p.getY() + p.getZ() * p.getZ() + p.getW() * p.getW();


Quat

4-tuple representing a rotation

A 4-tuple representing a rotation rotation. The xyz represents the axis, and the w represents the angle.

EXAMPLES

dmVMath::Quat p = dmVMath::Quat(x, y, z, w); // Create new rotation. W is the angle


Matrix3

3x3 matrix

A 3x3 matrix


Matrix4

4x4 matrix

A 4x4 matrix


Dot(a, b)

dot product between two vectors

dot product between two vectors

PARAMETERS

a - the first vector

b - the second vector

RETURN

dot_product - the dot product


Dot(a, b)

dot product between two vectors

dot product between two vectors

PARAMETERS

a - the first vector

b - the second vector

RETURN

dot_product - the dot product


Length(v)

calculate length of a vector

calculate length of a vector

PARAMETERS

v - the vector

RETURN

length - the length


Length(v)

calculate length of a vector

calculate length of a vector

PARAMETERS

v - the vector

RETURN

length - the length


Length(v)

calculate length of a quaternion

calculate length of a quaternion

PARAMETERS

v - the quaternion

RETURN

length - the length


Length(v)

calculate squared length of a vector

calculate squared length of a vector

PARAMETERS

v - the vector

RETURN

length - the squared length


Length(v)

calculate squared length of a vector

calculate squared length of a vector

PARAMETERS

v - the vector

RETURN

length - the squared length


Length(v)

calculate squared length of a quaternion

calculate squared length of a quaternion

PARAMETERS

v - the vector

RETURN

length - the squared length


Normalize(v)

normalize a vector to length 1

normalize a vector to length 1

PARAMETERS

v - the vector

RETURN

n - the normalized vector


Normalize(v)

normalize a vector to length 1

normalize a vector to length 1

PARAMETERS

v - the vector

RETURN

n - the normalized vector


Normalize(v)

normalize a quaternion to length 1

normalize a quaternion to length 1

PARAMETERS

v - the quaternion

RETURN

n - the normalized quaternion


Lerp(t, a, b)

linear interpolate between two vectors

linear interpolate between two vectors

PARAMETERS

t - the unit time

a - the start vector (t == 0)

b - the end vector (t == 1)

RETURN

v - the result vector v = a + (b - a) * t

EXAMPLES

dmVMath::Vector3 v0 = dmVMath::Lerp(0.0f, a, b); // v0 == a
dmVMath::Vector3 v1 = dmVMath::Lerp(1.0f, a, b); // v1 == b
dmVMath::Vector3 v2 = dmVMath::Lerp(2.0f, a, b); // v2 == a + (b-a) * 2.0f


Lerp(t, a, b)

linear interpolate between two vectors

linear interpolate between two vectors

PARAMETERS

t - the unit time

a - the start vector (t == 0)

b - the end vector (t == 1)

RETURN

v - the result vector v = a + (b - a) * t

EXAMPLES

dmVMath::Vector4 v0 = dmVMath::Lerp(0.0f, a, b); // v0 == a
dmVMath::Vector4 v1 = dmVMath::Lerp(1.0f, a, b); // v1 == b
dmVMath::Vector4 v2 = dmVMath::Lerp(2.0f, a, b); // v2 == a + (b-a) * 2.0f


Slerp(t, a, b)

spherical linear interpolate between two vectors

spherical linear interpolate between two vectors

PARAMETERS

t - the unit time

a - the start vector (t == 0)

b - the end vector (t == 1)

RETURN

v - the result vector


Slerp(t, a, b)

spherical linear interpolate between two vectors

spherical linear interpolate between two vectors

PARAMETERS

t - the unit time

a - the start vector (t == 0)

b - the end vector (t == 1)

RETURN

v - the result vector


Slerp(t, a, b)

spherical linear interpolate between two vectors

Interpolates along the shortest path between two quaternions

PARAMETERS

t - the unit time

a - the start vector (t == 0)

b - the end vector (t == 1)

RETURN

v - the result vector


DivPerElem(a, b)

divide two vectors per element

Divide two vectors per element: Vector3(a.x/b.x, a.y/b.y, a.z/b.z)

PARAMETERS

a - the operand

b - the dividend

RETURN

v - the result vector


DivPerElem(a, b)

divide two vectors per element

Divide two vectors per element: Vector3(a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w)

PARAMETERS

a - the operand

b - the dividend

RETURN

v - the result vector


Cross(a, b)

cross product between two vectors

cross product between two vectors

PARAMETERS

a - the operand

b - the dividend

RETURN

v - the result vector


MulPerElem(a, b)

multiply two vectors per element

Multiply two vectors per element: Vector3(a.x * b.x, a.y * b.y, a.z * b.z)

PARAMETERS

a - the first vector

b - the second vector

RETURN

v - the result vector


MulPerElem(a, b)

multiply two vectors per element

Multiply two vectors per element: Vector3(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)

PARAMETERS

a - the first vector

b - the second vector

RETURN

v - the result vector


MulPerElem(v)

abs value per element

Return absolute value per element: Vector3(abs(v.x), abs(v.y), abs(v.z))

PARAMETERS

v - the vector

RETURN

r - the result vector


MulPerElem(q)

conjugate of quaternion

Returns the conjugate of the quaternion: conj = -q

PARAMETERS

q - the quaternions

RETURN

r - the result


Rotate(q, v)

rotate vector using quaternion

rotate vector using quaternion

PARAMETERS

q - the rotation

v - the vector

RETURN

r - the rotated vector


Transpose(m)

transpose matrix

transpose matrix

PARAMETERS

m - the rotation

RETURN

r - the transposed matrix


Transpose(m)

transpose matrix

transpose matrix

PARAMETERS

m - the rotation

RETURN

r - the transposed matrix


Inverse(m)

inverse matrix

inverse matrix

PARAMETERS

m - the rotation

RETURN

r - the transposed matrix


Inverse(m)

inverse matrix

inverse matrix

PARAMETERS

m - the rotation

RETURN

r - the transposed matrix


OrthoInverse(m)

Compute the inverse of a 4x4 matrix, which is expe...

Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix with an orthogonal upper-left 3x3 submatrix

PARAMETERS

m - the rotation

RETURN

r - the transposed matrix


AppendScale(m, v)

post multiply scale

post multiply scale

PARAMETERS

m - the matrix

v - the scale vector

RETURN

r - the scaled vector