1

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?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Tofandel
  • 3,006
  • 1
  • 29
  • 48
  • This question appears to be off-topic because it is about a geometric formula, not programming. – Lorenz Meyer May 08 '14 at 17:00
  • Well It's actually a programming question since I need this for programmation purposes in a C# WPF application. I'm a little lost because I can't find something on the web or anywhere.. – Tofandel May 08 '14 at 17:01
  • Also I can put some code that I'm working on, but it's absolutely not what I want with the quaternion so I think that might be a little confusing – Tofandel May 08 '14 at 17:15
  • 1
    See also http://stackoverflow.com/a/23414774/3088138 – Lutz Lehmann May 08 '14 at 17:17
  • Thanks for the link, it's not a real answer but I think I can work with that – Tofandel May 08 '14 at 17:23
  • In the related topic I found something close to my question : http://stackoverflow.com/questions/2281864/translate-local-quaternion-rotation-into-global-gyro?rq=1 – Tofandel May 08 '14 at 17:25

1 Answers1

1

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

Community
  • 1
  • 1
Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51