Skip to content

Modern Math ToMatrix

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Math Library › Math Library › ToMatrix

ToMatrix

Converts a quaternion into the matching rotation matrix.

Syntax

ToMatrix( byref q as Quat ) as Mat4

Notes

  • Worth doing when many vectors are to be rotated: the conversion costs once and each transform is then a matrix multiply.
  • Assumes the quaternion is normalised.
  • The result is orthonormal, so its Transpose is its inverse.

Examples

#import "std/numeric"
using numeric

dim as Quat q = type<Quat>( 0, 0, 0, 1 )      '' identity
dim as Mat4 m = ToMatrix( q )

print m.m( 0 )               '' 1
print Determinant( m )       '' 1 -- a rotation preserves volume

Library: Math Library
Category: Math Library
Documented under: Members

Clone this wiki locally