In http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles

is a formula what - with the following input values - will outputes an
orthogonal matrix and a vector rotation

  s1=.sind 30
  c1=.cosd 30
  s2=.sind 45
  c2=.cosd 45
  s3=.sind 60
  c3=.cosd 60

  ]R11=.c2*c3
0.353553
  ]R12=.(-c1*s3)+s1*s2*c3
_0.573223
  ]R13=.(s1*s3)+c1*s2*c3
0.739199
  ]R21=.c2*s3
0.612372
  ]R22=.(c1*c3)+s1*s2*s3
0.739199
  ]R23=.(-s1*c3)+c1*s2*s3
0.28033
  ]R31=.-s2
_0.707107
  ]R32=.s1*c2
0.353553
  ]R33=.c1*c2
0.612372

  ]R=.3 3$R11,R12,R13,R21,R22,R23,R31,R32,R33
0.353553 _0.573223 0.739199
0.612372  0.739199  0.28033
_0.707107  0.353553 0.612372

  X=.+/ .*

  w=.3 4 5

  R X w
2.46376 6.19556 2.35475

In the Studio/Labs/rotations (with the same input values)
with the verbs

  r=: (cosd , -@:sind) ,. (sind , cosd)

  GR=: 4 : 0
res=: (i. =/ i.) 3       NB. Initialize res as identity matrix
p=: >0 1 2;1 0 2;1 2 0   NB. Permutations for axes
while. 0<# x do.
cp=. ('xyz'i.{:x){p                 NB. Current permutation
cr=. cp {"1 cp { 1 0 0,0 0,.r {: y  NB. Current rotation
res =. cr X res
x=. }: x
y=. }: y
end.
res
)

there is the same numerical example, but instead of R there is as resultat
an other rotation matrix:

  'xyz' GR 30 45 60
0.353553 0.612372 0.707107
_0.926777 0.126826 0.353553
0.126826 _0.78033 0.612372

instead of
  ]R=.3 3$R11,R12,R13,R21,R22,R23,R31,R32,R33
0.353553 _0.573223 0.739199
0.612372  0.739199  0.28033
_0.707107  0.353553 0.612372

After the refinement of verbs slightly we can get the same
resultats. Namenly

let be            r=: (cosd , -@:sind) ,:(sind , cosd)
instead of      r=: (cosd , -@:sind) ,. (sind , cosd)

and

   GR=: 4 : 0
res=: (i. =/ i.) 3       NB. Initialize res as identity matrix
p=: >0 1 2;2 0 1;1 2 0   NB. Permutations for axes
while. 0<# x do.
cp=. ('xyz'i.{:x){p                 NB. Current permutation
cr=. cp {"1 cp { 1 0 0,0 0,.r {: y  NB. Current rotation
res =. res X cr
x=. }: x
y=. }: y
end.
res
)

insted of

  GR=: 4 : 0
res=: (i. =/ i.) 3       NB. Initialize res as identity matrix
p=: >0 1 2;1 0 2;1 2 0   NB. Permutations for axes
while. 0<# x do.
cp=. ('xyz'i.{:x){p                 NB. Current permutation
cr=. cp {"1 cp { 1 0 0,0 0,.r {: y  NB. Current rotation
res =. cr X res
x=. }: x
y=. }: y
end.
res
)

Any opinion?

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

Reply via email to