# [PD] 3D Look at

pvallet publicat51 at free.fr
Thu Jun 28 14:46:16 CEST 2012

```I apologize, i should have "replied to list"...

Not very sure, but according to my fuzzy memory, one advantage of
quaternions is that you can compose many rotations by simply multiplying
quaternions together, which is quicker than building matrices for each
transform, and compute a final transform matrix (which can express also
translations and scalings) only at the end. I don't recall the details
there so you'll have to check the exact math.
i see here (wikipedia) something like

A quaternion q(x,y,z,w) can be expressed as a 3x3 rotation matrix
| 1-2(y*y)-2(z*z)   2xy-2zw             2xz+2yw          |
q=|  2xy+2zw           1-2(x*x)-2(z*z)   2yz-2xw           |
|  2xz-2yw             2yz+2xw           1-2(x*x)-2(y*y) |

which you an then matrix multiply with the other transforms to get the
final result.

So in PD you might want to use a matrix to express the whole transform
rather than
just  [rotateXYZ].  I don't know if you find this in gem, but it should
be there.

hope this helps,
Pierre.

Le 27/06/2012 12:10, Roch Jub a écrit :
> Hey Pierre !
>
> So I should convert to quaternion, then back to degreees ? or else how
> would I make a quaternion interact with [rotateXYZ] ?
>
> and also in the cart2sph, there is 3 outlets,
>
> the first one is R, it's not used in demo but what is it ? second is phi
> and theta that I know :)
>
> cheers
>
> 2012/6/27 pvallet <publicat51 at free.fr <mailto:publicat51 at free.fr>>
>
>     One major problem with euler rotations is that you can't, except in
>     trivial cases, smoothly interpolate betwen two rotation values. So
>     you might want to use quaternions for solving this. Basically a
>     quaternion is a 4D vector, expressing a direction (x,y,z) and a
>     "rotational" or "spin" (w) around this direction. Not that i'm
>     fluent with the math involved but when you interpolate between two
>     quaternions, you go smoothly along a straight arc between A  and B
>     position.
>     A search for "expressing rotations using quaternons" should give you
>     the pointers to the math you'll need.
>
>     cheers
>     Pierre
>
>
>     Le 26/06/2012 15:54, Roch Jub a écrit :
>
>         Hey !
>
>
>         So I send a mail some time ago to the list and got no answer, so
>         I guess
>         it was not really clear.
>
>         I come now with a more simple version of my problem.
>
>         I have two cubes,
>
>         cube A
>         translationXYZ 0 0 0
>         rotationXYZ 0 0 0
>
>         and cube B
>         translationXYZ 12 5 6
>         rotationXYZ 0 0 0
>
>         now I want to calculate with only thoses informations, the
>         rotations in
>         X Y and Z for cube A to look at cube B. (numbers are irrelevent,
>         I want
>         to make the algorythme)
>
>         I have tryed many things, with trigonometry, learned about
>         Gimbal lock,
>         read everything I could about euler angles, etc ... result is
>         it's not
>         working right.
>
>         I attached an exemple patch. The math inside are based on the
>         help I got
>         on a math forum. It quite look like the thing I was trying to do
>         but it
>         doesn"t work better :)
>
>         Anybody ? Any idea?
>
>         cheers
>
>         PS : I try to do that to calculate joint orientations of kinect
>         skeleton. and even though there might be other solutions(wich I
>         to know about), now it's a personal affair, I WANT TO DO IT !!!
>         2 WEEKS
>         I'VE BEEN TRYING !! AAARGH
>
>
>
>         _________________________________________________
>         Pd-list at iem.at <mailto:Pd-list at iem.at> mailing list
>         UNSUBSCRIBE and account-management ->
>         http://lists.puredata.info/__listinfo/pd-list
>         <http://lists.puredata.info/listinfo/pd-list>
>
>
>

```