# ArcBall Rotation

## Recommended Posts

kdworld    122
Hi Friends, I want to do arcball rotation , i found that most of implementations are using quaternions for rotation . (For the arbitary axis in the source sphere). It is also possible with matrices to rotate around arbitary axis. Then why quaternions are popular ? (since here we don't need any interpolation stuffs) Any nice thoughts ? KD Hard work never fails.

##### Share on other sites
Sc4Freak    643
Quaternions have a lot of nice properties. Quaternions only require 4 floats, which is a lot less than the 16 floats required for a 4x4 matrix (or 9 for a 3x3 matrix). Quaternions are also a lot faster, since a quaternion multiplication is far simpler and faster than a matrix multiplication.

Quaternions, like matrices, aren't very prone to gimbal locks. And, as you mentioned, they're useful when interpolating. The only downside to quaternions is that the math behind them can be a bit difficult to understand for some people.

##### Share on other sites
SiCrane    11839
One of the more important operations involved in arcball rotation is the calculation of the rotation to perform a rotation across shortest arc between two vectors. The calculation of this value for quaternions can look something like:
d = a <dot> b;s = sqrt((1 + d) * 2)c = a <cross> b;q = Quaternion(s / 2, c.x / s, c.y / s, c.z / s)

(This is missing things like error checks and special handling for when a and b are parallel.) The equivalent code for matrices is a little more involved.

Also, since arcball rotations involve storing the successive results of applied rotations, orientation is subject to numerical instability thats easier to compensate for with quaternions than with matrices.

Neither of these things are impossible with matrices, it's just easier with quaternions.

##### Share on other sites
kdworld    122
Thank you all for the replies.. It makes things more clear.