rtgs.utils.quaternion

Quaternion utils functions in Taichi.

Module Contents

Functions

mul

Quaternion multiplication.

conj

The complex conjugate of a quaternion.

inv

The inverse of a quaternion.

from_axis_angle

Convert a vector in axis-angle representation to quaternion.

as_axis_angle

Convert a quaternion into axis-angle representation.

rot_vec3

Rotate a vector v using a quaternion q.

as_rotation_mat3

Convert a vec4 quaternion to a 3x3 rotation matrix.

as_rotation_mat4

Convert a vec4 quaternion to a 4x4 rotation matrix in homogeneous coordinate.

API

rtgs.utils.quaternion.mul(p, q)

Quaternion multiplication.

Parameters:
  • p (ti.math.vec4) – left quaternion.

  • q (ti.math.vec4) – right quaternion.

Returns:

multiplication result pq.

Return type:

ti.math.vec4

rtgs.utils.quaternion.conj(q)

The complex conjugate of a quaternion.

Parameters:

q (ti.math.vec4) – input quaternion.

Returns:

the complex conjugate of q.

Return type:

ti.math.vec4

rtgs.utils.quaternion.inv(q)

The inverse of a quaternion.

Parameters:

q (ti.math.vec4) – input quaternion.

Returns:

the inverse of q.

Return type:

ti.math.vec4

rtgs.utils.quaternion.from_axis_angle(v)

Convert a vector in axis-angle representation to quaternion.

Parameters:

v (ti.math.vec3) – axis-angle represented vector with v pointing to the direction of the rotation and length of v equals to the angle to rotate.

Returns:

rotation quaternion.

Return type:

ti.math.vec4

rtgs.utils.quaternion.as_axis_angle(q)

Convert a quaternion into axis-angle representation.

Parameters:

q (ti.math.vec4) – a unit quaternion.

Returns:

axis-angle representation of q

Return type:

ti.math.vec3

rtgs.utils.quaternion.rot_vec3(q, v)

Rotate a vector v using a quaternion q.

Parameters:
  • q (ti.math.vec4) – quaternion q.

  • v (ti.math.vec3) – vector v.

Returns:

the rotated vector v using quaternion q (as $qvec{v}q^{*}$).

Return type:

ti.math.vec3

rtgs.utils.quaternion.as_rotation_mat3(q)

Convert a vec4 quaternion to a 3x3 rotation matrix.

Parameters:

q (ti.math.vec4) – a normalized quaternion.

Returns:

a 3x3 rotation matrix in homogeneous coordinate.

Return type:

ti.math.mat3

rtgs.utils.quaternion.as_rotation_mat4(q)

Convert a vec4 quaternion to a 4x4 rotation matrix in homogeneous coordinate.

Parameters:

q (ti.math.vec4) – a normalized quaternion.

Returns:

a 4x4 rotation matrix in homogeneous coordinate.

Return type:

ti.math.mat4