Quaternion type: Difference between revisions
Content added Content deleted
Line 6,993: | Line 6,993: | ||
'a1*d2 + b1*c2 − c1*b2 + d1*a2' EVAL |
'a1*d2 + b1*c2 − c1*b2 + d1*a2' EVAL |
||
{ 4 } →ARRY |
{ 4 } →ARRY |
||
≫ ≫ '''' |
≫ ≫ ''''QMULT'''' STO |
||
| |
| |
||
'''QNORM''' ''( [ a b c d ] -- √(a²+b²+c²+d²) )'' |
'''QNORM''' ''( [ a b c d ] -- √(a²+b²+c²+d²) )'' |
||
Line 7,005: | Line 7,005: | ||
''' |
'''QMULT''' ''( [Q1] [Q2] -- [Q1 x Q2] )'' |
||
put the 2 quaternions in local variables |
put the 2 quaternions in local variables |
||
do the math in stack |
do the math in stack |
||
Line 7,023: | Line 7,023: | ||
[2 3 4 5] [3 4 5 6] + |
[2 3 4 5] [3 4 5 6] + |
||
[1 2 3 4] 7 * |
[1 2 3 4] 7 * |
||
[2 3 4 5] [3 4 5 6] |
[2 3 4 5] [3 4 5 6] QMULT |
||
[3 4 5 6] [2 3 4 5] |
[3 4 5 6] [2 3 4 5] QMULT |
||
</pre> |
</pre> |
||
Line 7,038: | Line 7,038: | ||
1: [ -56 18 20 28 ] |
1: [ -56 18 20 28 ] |
||
</pre> |
</pre> |
||
=== Quaternion multiplication through Cayley-Dickson construction=== |
|||
This is a shorter and faster version of the <code>QMULT</code> word. {{trans|Ruby}} |
|||
{| class="wikitable" |
|||
! RPL code |
|||
! Comment |
|||
|- |
|||
| |
|||
≪ |
|||
ARRY→ DROP R→C ROT ROT R→C ROT |
|||
ARRY→ DROP R→C ROT ROT R→C → d c b a |
|||
≪ a c * d CONJ b * - C→R |
|||
d a * b c CONJ * + C→R |
|||
{ 4 } →ARRY |
|||
≫ ≫ ''''QMULT'''' STO |
|||
| |
|||
'''QMULT''' ''( [Q1] [Q2] -- [Q1 x Q2] )'' |
|||
convert the 2 quaternions into complex numbers |
|||
and store them locally |
|||
(a,b)(c,d) = (ac - conj(d).b, // (a,b) and (c,d) are pairs |
|||
da + b.conj(c)) // of complex numbers |
|||
convert stack to a quaternion |
|||
|} |
|||
Output is the same. |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |