fwiw, I wrote a few Mickey-Mouse verbs yesterday while waiting for my virus-checker to go through its paces.  Mainly to get my head round the Cayley-Dickson complex duple representations. Here's a proto-script below my sign-off; for starters, I've assumed 2-column arrays, but rank 1 might not be the way to go (?) - I haven't got into
arrays of quaternions yet!

Mike

Apologies for any line-wrapping - it looks ok this end!
=======================================================================================
NB. Cayley-Dickson construction

NB. based on entries in
NB. https://en.wikipedia.org/wiki/Quaternion
NB. and
NB. https://en.wikipedia.org/wiki/Cayley-Dickson_construction

NB. Quaternion quadruple (a b c d) with a,b,c,d e. ℝ is stored as a complex duple ajb cjd  e. ℂ2

NB. conjugate of complex duple q = (a,b) is q* = (a*, -b) where * is complex conjugate

NB. Addition       (a,b) + (c,d) = (a+b, c+d) ... so dyad + works without needing modification

NB. Multiplication (a,b) * (c,d) = (ac-b.d*, ad+b.c*),  where * is comp conj
NB.                              = (a,b) +/ . * (c d*)
NB.                                             (d c*)  <== 2x2 complex matrix

NB. Magnitude
NB.    magnitude squared of (a,b), ||(a,b)||^2  = |a|^2 + |b|^2 e. ℝ where |a| is magnitude of complex a

NB. Reciprocal     (a,b)^_1 = (a*, -b)% ||(a,b)||^2

NB. Norm
NB.    (magnitude, 0)   e.  ℝ2 e. ℂ2      - not sure why it needs to be a quaternion!?

NB. complex verbs
cconj   =: +
cnormsq =: *+
cnorm   =: %: @ cnormsq

NB. Quaternion verbs
qconj  =: ((cconj@[,-@])/)"1                     NB. conjugate of (a,b)
qmult  =: (+/ . * (,:_1 1 * |. @: cconj))"1      NB. multiply (a,b)*(c,d)
qmagsq =: (+/ @: cnormsq)"1                      NB. Magnitude squared
qmag   =: %: @ qmagsq                            NB. Magnitude
qnorm  =: (0,~ qmag)"1                           NB. Norm
qscalar=: (-: @ (+ qconj))"1                     NB. "Scalar" part
qvector=: (-: @ (- qconj))"1                     NB. "Vector" part
qrecip =: ((cconj@[, -@])/ % qmagsq)"1           NB. Reciprocal
qdivl  =: qmult qrecip                           NB. via left quotient  - cribbed from Zhuravlov qdivr  =: qmult~qrecip                           NB. via right quotient - cribbed from Zhuravlov

NB.    1j2 3j4 qmult 5j6 7j8
NB. _60j12 30j24
NB.
NB.    _60j12 30j24 qdivl 5j6 7j8
NB. 1j2 3j4
NB.
NB.    _60j12 30j24 qdivr 1j2 3j4
NB. 5j6 7j8

On 01/11/2018 19:38, Raul Miller wrote:
Rotations can be dizzying to think about, so this sort of issue is
maybe best visited casually over a period of time rather than jammed
into an intensive study session.

That said, the wikipedia page on Gimbal Lock can help motivate an
understanding of why a person might want to use quaternions to
represent rotation in three dimensions.

Thanks,



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to