9.0
top
← prev up next →

QuaternionπŸ”— i

APOS80

1IntroπŸ”— i

Quaternions are used for rotation of koordinates and vectors.

2StructuresπŸ”— i

struct

(struct qvector(xyz)
#:mutable
#:transparent)

struct

(struct quaternion(wv)
#:mutable
#:transparent)
v:qvector?

3Basic proceduresπŸ”— i

procedure

( q-addq1q2)quaternion?

q1:(quaternion?)
q2:(quaternion?)

procedure

( q-subq1q2)quaternion?

q1:(quaternion?)
q2:(quaternion?)

procedure

( q-normq)quaternion?

q:(quaternion?)

procedure

( q-normalizeq)quaternion?

q:(quaternion?)

procedure

( q-multiply-qqq1q2)quaternion?

q1:(quaternion?)
q2:(quaternion?)

procedure

( q-divide-qsqs)quaternion?

q:(quaternion?)
s:(flonum? )

procedure

( q-negateq)quaternion?

q:(quaternion?)

procedure

( q-conjugateq)quaternion?

q:(quaternion?)

procedure

( q-inverseq)quaternion?

q:(quaternion?)

4RotationπŸ”— i

procedure

( q-rotationanglqv)quaternion?

angl:(flonum? )
qv:(qvector?)
Rotation in radians about an arbitrary axis. Positive rotation is anticlockwise!

procedure

( q-rotaterotationobject)quaternion?

rotation:(quaternion?)
object:(quaternion?)
Applyes the rotation on an object. Object quaternion’s w has to be 0!

5ExamplesπŸ”— i

;Rotation about one axis:
(let*
([A(q-rotation(fl/ pi 2.0)(qvector0.01.00.0))];Rotation 90degrees about Y-axis.
[B(q-rotateA(quaternion0.0(qvector0.00.01.0)))]);Apply rotation on quaternion with A.
(printf "X: ~a\n"(~r (qvector-x(quaternion-vB))));Print results.
(printf "Y: ~a\n"(~r (qvector-y(quaternion-vB))))
(printf "Z: ~a\n"(~r (qvector-z(quaternion-vB))))))
;Rotation about two axis:
(let*
([A1(q-rotation(fl/ pi 4.0)(qvector0.01.00.0))];Rotation 90degrees about Y-axis.
[A2(q-rotation(fl/ pi 4.0)(qvector1.00.00.0))];Rotation 90degrees about X-axis.
[AS(q-multiply-qqA1A2)];Combine rotations.
[B(q-rotateAS(quaternion0.0(qvector0.00.01.0)))]);Apply rotation on quaternion with A.
(printf "X: ~a\n"(~r (qvector-x(quaternion-vB))));Print results.
(printf "Y: ~a\n"(~r (qvector-y(quaternion-vB))))
(printf "Z: ~a\n"(~r (qvector-z(quaternion-vB))))))
top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /