8.16.0.1
Quaternions are used for rotation of koordinates and vectors.
|
#:mutable |
#:transparent) |
w : flonum? |
v : qvector? |
3 Basic procedures🔗ℹ
(q-add q1 q2) → quaternion?
|
q1 : (quaternion?) |
q2 : (quaternion?) |
(q-sub q1 q2) → quaternion?
|
q1 : (quaternion?) |
q2 : (quaternion?) |
(q-norm q) → quaternion?
|
q : (quaternion?) |
(q-normalize q) → quaternion?
|
q : (quaternion?) |
(q-multiply-qq q1 q2) → quaternion?
|
q1 : (quaternion?) |
q2 : (quaternion?) |
(q-divide-qs q s) → quaternion?
|
q : (quaternion?) |
s : (flonum?) |
(q-negate q) → quaternion?
|
q : (quaternion?) |
(q-conjugate q) → quaternion?
|
q : (quaternion?) |
(q-inverse q) → quaternion?
|
q : (quaternion?) |
(q-rotation angl qv) → quaternion?
|
angl : (flonum?) |
qv : (qvector?) |
Rotation in radians about an arbitrary axis.
Positive rotation is anticlockwise!
(q-rotate rotation object) → quaternion?
|
rotation : (quaternion?) |
object : (quaternion?) |
Applyes the rotation on an object.
Object quaternion’s w has to be 0!
; Rotation about one axis: |
(let* |
([A (q-rotation (fl/ pi 2.0) (qvector 0.0 1.0 0.0))]; Rotation 90degrees about Y-axis. |
[B (q-rotate A (quaternion 0.0 (qvector 0.0 0.0 1.0)))]); Apply rotation on quaternion with A. |
(begin |
(printf "X: ~a\n" (~r(qvector-x (quaternion-v B)))); Print results. |
(printf "Y: ~a\n" (~r(qvector-y (quaternion-v B)))) |
(printf "Z: ~a\n" (~r(qvector-z (quaternion-v B)))))) |
; Rotation about two axis: |
(let* |
([A1 (q-rotation (fl/ pi 4.0) (qvector 0.0 1.0 0.0))]; Rotation 90degrees about Y-axis. |
[A2 (q-rotation (fl/ pi 4.0) (qvector 1.0 0.0 0.0))]; Rotation 90degrees about X-axis. |
[AS (q-multiply-qq A1 A2)]; Combine rotations. |
[B (q-rotate AS (quaternion 0.0 (qvector 0.0 0.0 1.0)))]); Apply rotation on quaternion with A. |
(begin |
(printf "X: ~a\n" (~r(qvector-x (quaternion-v B)))); Print results. |
(printf "Y: ~a\n" (~r(qvector-y (quaternion-v B)))) |
(printf "Z: ~a\n" (~r(qvector-z (quaternion-v B)))))) |