# commons-user mailing list archives

##### Site index · List index
Message view
Top
From Luc Maisonobe <Luc.Maison...@free.fr>
Subject Re: [Math] Rotating around global z-axis in processing
Date Thu, 20 May 2010 21:47:51 GMT
```Le 20/05/2010 23:00, Markus Petschnigg a écrit :
> Hi!
>
> We are building an application where we rotate and translate boxes with
> different Wiimote metaphors in Processing.
> We want to rotate an object around the global processing canvas z-axis,
> not around the objects own z-axis. No matter which rotation has been
> used before, no matter where the object is in the canvas, this should
> just rotate the object around the Processing z-axis. We are using the
> Shapes3D libary which is based on apache commons math. The method used
> for rotating is called Rot, which is basically the same as in the apache
> commons math.
> Here is a link to the processing forum, where we also discussed the
> issue: http://processing.org/discourse/yabb2/YaBB.pl?num=1272357250/15
> Our entire code is online at: http://code.google.com/p/3d-media-browser/

I would suggest to compute the coordinates of the canvas Z axis in the
object frame and to rotate the object around this axis.
I assume you have some methods to get or set the orientation fo your
object with respect to the canvas. For the sake of the example, I will
assume the API is something like :
Rotation r1 = myObject.getOrientation();
and
myObject.setOrientation(r2);

The assumed semantic is that v = r1(u) is such that if u is a vector in
object reference frame, v is the vector in the canvas reference frame,
i.e. myObject.getOrientation().applyTo(Vector3D.PLUS_K) gives the
orientation of the Z axis of the object in the canvas frame. What you
want is the opposite, so you have to revert the rotation.

You could use something along these lines :

Vector3D zAxis =
myObject.getOrientation().revert().applyTo(Vector3D.PLUS_K);

This vector is the canvas Z axis in the object frame. So if you apply a
rotation to the object around this axis, it will rotate around an axis
parallel to the canvas Z axis, but containing object origin.

If you don't have a getOrientation() method with the assumed semantic,
you will have to reconstruct the rotation by yourself. One way to do
this is to use the coordinates of two canonical axes of the object as
follows:

public Rotation getOrientation() {

// get the direction of object X axis with respect to canvas frame
Vector 3D objectXAxis = ...;

// get the direction of object Y axis with respect to canvas frame
Vector 3D objectYAxis = ...;

return new Rotation(Vector3D.PLUS_I, Vector3D.PLUS_J,
objectXAxis, objectYAxis);

}

Hope this helps,
Luc

>
> Markus
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org