Rotation in 3D with 4D digits
                (tesseral arithmetic - digit by digit)

S.B.M. Bell and D.C. Mason: Tesseral Quaternions for the Octtree
THE COMPUTER JOURNAL, Vol. 33, No. 5, 1990, pp. 386-397

    Confugure: "Arial Unicode MS" 16

The "qabc" (quaternion-abc)
  qabc=:81
3$'o̥ḀB̥C̥D̥E̥F̥G̥H̥I̥J̥K̥L̥M̥N̥O̥P̥Q̥R̥S̥T̥U̥V̥W̥X̥Y̥Z̥o̟A̟B̟C̟D̟E̟F̟G̟H̟I̟J̟K̟L̟M̟N̟O̟P̟Q̟R̟S̟T̟U̟V̟W̟X̟Y̟Z̟o̠A̠B̠C̠D̠E̠F̠G̠H̠I̠J̠K̠L̠M̠N̠O̠P̠Q̠R̠S̠T̠U̠V̠W̠X̠Y̠Z̠
'

The "vabc" (vector-abc)
vabc=:'@ABCDEFGHIJKLMNOPQRSTUVWXYZ'

  d=:3 :'q,"1 y,"1 q=.39{a.'    NB. display of quaternion

  AfC=: 3 : 0   NB. conversion to "alfa form" from "coordinate form"
A=.4 0$0
while.+./0~:y do.y=.3%~y-j-3*j=2[A=.A,.~|.j=.3|y end.
qabc{~3#.|:A
)
                      NB. conversion to "coordinate form" from "alfa form"
  CfA=:3 :'3#.|.|:j-3*2=j=.3 3 3 3#:qabc i.y$~3,~3%~#y'

   IfC=: 3 : 0   NB. conversion to "alfa-indexes" from "coordinate form"
A=.4 0$0
while.+./0~:y do.y=.3%~y-j-3*j=2[A=.A,.~|.j=.3|y end.
3#.|:A
)
                      NB.conversion to "balanced ternary form" from "index
form"
   TfI=:3 : '|."1 j-3*2=j=.3 3 3 3#:y'

   TfC=: 3 : 0   NB. conversion to "balanced ternary form" from "deci form"
A=.4 0$0
while.+./0~:y do.y=.3%~y-j-3*j=2[A=.A,.~|.j=.3|y end.
|."1 j-3*2=j=.|:A
)

   TfA=: 3 : 0   NB. conversion to "balanced ternary form" from "alfa form"
A=.4 0$0[y=.CfA y
while.+./0~:y do.y=.3%~y-j-3*j=2[A=.A,.~|.j=.3|y end.
|."1 j-3*2=j=.|:A
)

  afd=: 3 : 0   NB. conversion to "alfa form" from "deci form"
if. 0=+/|y do. A=.'@'
         else.
         A=.''
while.+./0~:y do.y=.3%~y-j-3*j=2[A=.A,~vabc{~3#.|.j=.3|y end.
end.
A
)
                      NB. conversion to "deci form" from "alfa form"
 dfa=:3 :'3#.|.|:j-3*2=j=.3 3 3 3#:,,.vabc i.y'

    HELMERT=: 4 : 0         NB. (x= vector) rotation and scaling (y=
quaternion)
print=: 1!:2&2
W=:0 0 0                            NB.  clear the accumulator
qt=:TfA y                            NB.  quaternion in balanced ternary
form
qk=: _1 _1 _1 1*"1 qt         NB.  conjugated quaternion
V=:dfa x                             NB.   vector in "deci form"

signums=:4 4$1 _1 1 1 1 1 _1 1 _1 1 1 1 _1 _1 _1 1
indexes=:4 4$3 2 1 0 2 3 0 1 1 0 3 2 0 1 2 3
N=: #qt                               NB. number of digits in quaternion
for_i. i.(2*N)-1 do.               NB. interval to i-cycle
 indent=:14+4*i                  NB. intend to partial products
 Kf=:ij*0<ij=.i-N-1               NB. first value of i-cycle
 Kl=:<.i%2                          NB.  last value of i-cycle
 for_k. Kf}.i.Kl+1 do.           NB. interval to k-cycle
   l=: i-k                               NB. index of qk
   h=: 3^((2*N)-i+2)             NB. place value of partial product
   KL=: k{qt                         NB. the left hand of quaternion's
digit
   KR=: l{qk                         NB. the right hand of quaternion's
digit
   KL_V=: (signums*indexes{KL) (+/ .*) V   NB. multiplication V from
left
   KL_V_KR=: }:(signums*indexes{KL_V) (+/ .*) KR   NB. multiplication from
right
   if.k~:l do. KL_V_KR=: 2*KL_V_KR end.  NB. joint the offdiagonal
elements
   W=: W+KL_V_KR*h         NB. accumulation of partial products
   WW=:afd KL_V_KR         NB. partial product from deci to alfa form
   WW=:(-indent){.WW         NB. moving of partial product
   print WW,(30$' '),5":KL_V_KR NB. write the partial product
 end.                                   NB. end of k-cycle
end.                                     NB. end of i-cycle
if. 1<#qt do.                         NB.  conversion of final product
  SZ=:afd W                        NB.  from deci form to alfa form
  G=.(-indent){.F=.'-'#~2*#SZ  NB. underscore of partial products
  print  G,(30$' '),F               NB. write the underscore
  print SW=:((-indent){.SZ),(30$' '),":x:W NB. write the final product
end.
' '
)

Example No. 1      (with abstract data)

   dfa 'LY'                  NB.  x y z s - 3D vector    in 4D (quaternion)
form
1 2 2 0                       NB.               converted into 3D
(alphabetic) form
  afd 1 2 2 0              NB.               in order to be rotated and
scaled
LY                              NB.               (back-and-forth
conversion)

 CfA 'I̥D̟T̠'                  NB. X Y Z S - 4D vector (quaternion) in deci
form
2 3 8 2                       NB.                converted into 4D
(alphabetic) form
 ,AfC 2 3 8 2             NB.   contains the transformation
parameters:
I̥D̟T̠                            NB.   rotation-axis, -angle and
magnification

 'LY' HELMERT 'I̥D̟T̠'           1 2 2  rotation  2 3 8 2
           OW                                 _1   _2    2
              LX@                                  0    6    6
                  RMH                                  2    2   _6
                  A@@                                  9    0    0
                      TT@                               _12    0  _12
                          IFY                                      1
_4    8
           ------------------
------------------------------
                  [EMAIL PROTECTED]                               _17    14   
242

   dfa '[EMAIL PROTECTED]'          NB.  x y z s -    in    3D (alphabetic) form
_17 14 242 0               NB.  converted into 4D     (decimal) form.
   afd _17 14 242 0     NB.  It is the transformed vector obtained
[EMAIL PROTECTED]                      NB.  as the sum of partial products.

NB.============================================================

Example No. 2      (with abstract data)

   afd 17 _22 4 0        NB.  x y z s - 3D vector    in 4D (quaternion)
form
GEOQ                         NB.               converted into 3D
(alphabetic) form
   dfa 'GEOQ'             NB.                in order to be rotated and
scaled
17 _22 4 0                  NB.                (back-and-forth conversion)

  ,AfC _28 12 _6 11   NB. X Y Z S - 4D vector (quaternion) in deci form
B̥U̟L̟B̠                         NB.                converted into 4D
(alphabetic) form
  CfA 'B̥U̟L̟B̠'              NB.   contains the transformation
parameters:
_28 12 _6 11              NB.   rotation-axis, -angle and magnification

  'GEOQ' HELMERT 'B̥U̟L̟B̠'       17 _22 4   rotation _28 12 _6 11
         DHUW                                   17   22   _4
            [EMAIL PROTECTED]                                 52  _26   78
                 [EMAIL PROTECTED]                                 36  _26   10
                HMXRY                                _53  _64   14
                    RMDKS                                 34   36  _52
                    FVEIWT                               50 _132  _76
                        [EMAIL PROTECTED]                                 54   
52  104
                         RDPUQ                                  35   20
_74
                            BPLDG                                 _50
_16   36
                                RJPBM                                  34
_8  _44
        -------------------------------
------------------------------------
                      JSIUPGMJFM                        26605 430 14860

    dfa 'JSIUPGMJFM'            NB.  x y z s -    in    3D (alphabetic)
form
26605 430 14860 0                NB.  converted into 4D     (decimal) form.
    afd 26605 430 14860 0     NB.  It is the transformed vector obtained
JSIUPGMJFM                         NB.  as the sum of partial products.

NB.============================================================

Example No. 3      (with abstract data)

   dfa 'CCDXI'                        NB.  x y z s - 3D vector    in 4D
(quaternion) form
9 114 _2 0                              NB.                converted into 3D
(alphabetic) form
   afd 9 114 _2 0                    NB.                in order to be
rotated and scaled
CCDXI                                    NB.                (back-and-forth
conversion)

   CfA 'A̟Z̥o̥X̠o̟M̥'                    NB. X Y Z S - 4D vector
(quaternion) in deci form
163 _89 _89 237                   NB.                converted into 4D
(alphabetic) form
  ,AfC 163 _89 _89 237        NB.   contains the transformation
parameters:
A̟Z̥o̥X̠o̟M̥                                NB.   rotation-axis, -angle and
magnification

  'CCDXI' HELMERT 'A̟Z̥o̥X̠o̟M̥'     9 114 _2  rotation 163 _89 _89 237

       [EMAIL PROTECTED]                                            18    4  228
           UFCKIZ                                        _10  188 _232
                    @                                                 0
0    0
               JFHLRZ                                      215 _100  248
                [EMAIL PROTECTED]                                     _10 _268 
_224
                             @
0    0    0
                       [EMAIL PROTECTED]                                       
18
232  224
                      [EMAIL PROTECTED]                                      _44
32  684

@                                                0    0    0
                           OCFSRM                                       10
_188  232
                           [EMAIL PROTECTED]                                    
 232
_22 _210

@                                                 0    0    0
                              TMGEUDZ                                _430
200 _496

@                                                0    0    0
                                   NFXXDQ
_241  128  208

@                                                0    0    0
                                   [EMAIL PROTECTED]
214 _246   22
                                      [EMAIL PROTECTED]
44  _32 _684

CCDXI                                         9  114   _2
                                           [EMAIL PROTECTED]
_232   22  210

JFHLRZ                                    215 _100  248
                       --------------------------------
-------------------------------------------
                          [EMAIL PROTECTED]           2246072 2856440
10673204

  dfa '[EMAIL PROTECTED]'             NB.  x y z s -    in    3D
(alphabetic) form
2246072 2856440 10673204 0           NB.  converted into 4D     (decimal)
form.
  afd 2246072 2856440 10673204 0   NB.  It is the transformed vector
obtained
[EMAIL PROTECTED]                        NB.  as the sum of partial products.
Istvan Kadar

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

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

Reply via email to