Question

I'm working with quaternions and I have a little problem.

I have an object (The violet line) and a quaternion relative to the rotation axis (Black line), and I want to convert this quaternion in local space, so that the rotation axis become the object.

I need to calculate the roll of the object (Which will be the Y rotation in local space that I will convert to axis angle) and then calculate the X and Z rotation in Axis Angle.

Here is a scheme that I drew to a better understanding of the question :

Schema

To understand you can think of your shoulder, when you move your arm you have the X and Z which will determine the forearm position and the Y which will determine the rotation of your elbow.

Do not hesitate to ask for clarifications, since it can be hard to understand what I'm searching for.

Is there a formula or an algorithm that I can use to do so ?

Is there 3D programmers who worked with quaternions and who can clarify me on the subject with an algorithm or just words?

Was it helpful?

Solution

You are looking for a quaternion q, such that qjq'=n, where n is the imaginary unit quaternion representing the axis of the object. This has a standard solution in terms of the product jn, essentially the square root.

If

jn=c+s*e, e imaginary unit, c²+s²=1, s>=0

then

q = sqrt(0.5*(1+c)) + sqrt(0.5*(1-c))*e

so compute

p=j*n // condition is n is imaginary unit
c=real(p)
e=imag(p)
s=abs(e)
if(s>0) e=e/s else e=j 
s=sqrt(0.5*(1-c))
c=sqrt(0.5*(1+c))
q=c+s*e

See also https://stackoverflow.com/a/23414774/3088138

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top