views:

60

answers:

3

I have a 3D viewport that uses the TrackBall of WPF 3D tool to rotate the object by mouse. As a result, I get a single AxisAngleRotation3D with Axis vector like (0.5, 0.2, 0.6) and Angle of e.g. 35. That's fine.

What I would like to do is, as an alternative, to give user the ability to rotate the object by individual axis (i.e. x, y, z). So, if the object is rotated around the axis of (0.5, 0.2, 0.6) by 35 degree, how can I convert this into three rotations around each axis, ie. Xangle for vector (1, 0, 0), Yangle for vector (0, 1, 0), and Zangle for vector (0, 0, 1).

I also need a way to convert them back to a single AxisAngleRotation3D object.

A: 

You can convert it to a matrix and then back to three separate rotations representation. You can find formulas for both conversions on the net. You can also optimize it by writing it down and solving the equations on paper resulting in possibly faster formula.

However, I suggest to never represent rotation in three numbers, that's due to singularities resulting from this implementation and numeric instability. Use quaternions instead.

ybungalobill
A: 

@ybungalobill: This is exactly I'm looking for. so I'd appreciate very much if you could provide me those formulas. I couldn't find it, maybe because I don't understand it well.

miliu
Use "add comment" to make such comments, especially if you want me to answer.
ybungalobill
A: 

I found some stuff at http://www.gamedev.net/reference/articles/article1095.asp. One thing I learnt is that I can easily get a (combined) quaternion from separete AxisAngleRotation3D. For example,

        private AxisAngleRotation3D _axisX = new AxisAngleRotation3D();
        private AxisAngleRotation3D _axisY = new AxisAngleRotation3D();
        private AxisAngleRotation3D _axisZ = new AxisAngleRotation3D();
...
            _axisX.Axis = new Vector3D(1, 0, 0);
            _axisY.Axis = new Vector3D(0, 1, 0);
            _axisZ.Axis = new Vector3D(0, 0, 1); 
...
            Quaternion qx = new Quaternion(_axisX.Axis, _axisX.Angle);
            Quaternion qy = new Quaternion(_axisY.Axis, _axisY.Angle);
            Quaternion qz = new Quaternion(_axisZ.Axis, _axisZ.Angle);
            Quaternion q = qx * qy * qz;

This is fine. Now, the problem is how can I do the reverse? So, for a given q, how can I find out qx, qy, qz?

miliu
Go to http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29#Conversion_formulae_between_representations and you have the formulas.
ybungalobill