开发者

WPF 3D: How to convert a single AxisAngleRotation3D into separate AxisAngleRotation3D?

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开发者_如何学C 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.

EDIT:

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?


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.


cuanternion to Euler angles

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜