GMT

Discussion forum for GMT and Computer Science - Utrecht University chapter, The Netherlands

Logged as Anonymous. Your last visit was on

You are not connected. Please login or register

Post new topic  Reply to topic

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Quaternion to rotation axis + angle on Tue Sep 30, 2008 10:59 am

I'm enjoying the forum already! My first post is going to dive right in to third year bachelor level, so bear with me.

If you want to skip straight to the math, you're perfectly welcome to, I'm just giving a introductory description of where I am and what I'm trying to do.

Presently, I'm working on my experimentation project for which I am trying to accomplish the following:

I have a 3D recording (FBX) of person holding a device. I have developed an OpenCV-based application that projects the points from the FBX model upon a plane. (Incidentally, in such a way that they are distorted according to the lens parameters.)

The application simultaneously plays the video recorded on the device. The idea is to overlay the markers of the model onto the video and do some calculations with that. In order to accomplish this, the plane needs to be translated and rotated in such a way that it moves exactly in correspondence with the device.

Before I get to the problem, let me first show you what we're talking about. If I move the model some distance away from the plane (i.e. "camera") and rotate it such that the it's framed correctly, it looks like this:



(I've appropriately chosen an image of Phillip!)

By default, I place the camera at the origin (0,0,0) without any rotation (0,0,0). I cannot modify the way in which the plane is translated or rotated as this is done internally by OpenCV; I can only specify a translation and rotation vector.

Upon running the application, the camera appears to be aligned as shown in the image below.


(due to a bug: blue axis = X, green axis = Y, red axis = Z)
(the model is shown here face down; he is in fact standing in the T-pose with the device in his right hand)

First off, the axes don't point in the expected direction; Z should run vertically in the image. Regardless, I want the plane aligned according to the device, but I can't get my finger on how to solve this.

By manually rotating the camera to (0, 0, 0.5*pi) I can get it such that the axes appear correctly:



Due to the lack of documentation for OpenCV, I don't know what the rotation vector is actually supposed to do. However, it would then appear that the rotation vector is defined as a axis along which the rotation is performed, whose magnitude (i.e. length of the vector) is the angle (right-handed).

I say this, because a rotation of (0, 0.5*pi, 0.5*pi) does not rotate the model one half radian along the Y- and Z-axes, but instead results in something quite different:



I've tried to make things easier for myself by extracting the normal from the device (yellow line):



The resulting vector does not prove very useful either, however. There is one point in the recording where the normal gets close to an axis: (0.023, -0.706, -0.028). We could therefore, to simplify things, assume that the camera should be looking along the axis (0, -1, 0). By manually rotating the plane to look along that axis I get the rotation vector (1.085, -1.36, -1.015).

Now for the mathematical part to this dilemma.

I've gone ahead and assumed that the rotation vector is indeed a rotation axis and angle. To determine which axis and angle I need, I first need to:
  1. Construct a rotation matrix.

  2. Convert the matrix to a quaternion.

  3. Extract the rotation axis and angle from the quaternion.


I'm fairly certain that steps 1 and 2 are on target, but I'm thrown off by the last one. If I recall correctly from the master course Advanced Graphics, the rotation axis and angle from a quaternion is simply a normalized quaternion such that Qw = 1, right?

Any help would be so much appreciated!



Last edited by Paul on Tue Sep 30, 2008 12:32 pm; edited 1 time in total (Reason for editing : mixed up axis colors)

View user profile http://paul.luminos.nl

2 Re: Quaternion to rotation axis + angle on Tue Sep 30, 2008 11:22 am

I am further confused by this webpage, proposing a normalization function for quaternions:
http://www.flipcode.com/documents/matrfaq.html#Q57

The following Wikipedia article confirms my findings up until step 2:
http://en.wikipedia.org/wiki/Rotation_operator_%28vector_space%29#Numerical_example

In the meantime I have discovered how to compute the rotation axis:


However, I do not understand how θ = 44.537deg is obtained from the quaternion. I'm under the impression that it has something to do with reconsidering the rotation matrix, but I'm not sure how this comes into play:


Perhaps somebody can make more sense of this than I can?

View user profile http://paul.luminos.nl

3 Re: Quaternion to rotation axis + angle on Mon Oct 06, 2008 4:54 pm

my recommendation is to look at ogre3d quaternion implementation:
from the API docs: http://www.ogre3d.org/docs/api/html/classOgre_1_1Quaternion.html
I can see it does all the stuff you need. you can look at the c++ code and match it with the math theory you have so far.
success!

View user profile

4 Re: Quaternion to rotation axis + angle on Tue Oct 14, 2008 2:52 pm

Thanks, I'll be sure to take a look.

I've given it some thought and am probably going to keep the camera stationary and perform a rotation matrix on all the markers instead. I'll update this post with my findings when I find a good solution.

In the interest of completeness, I'll also review rotating the camera such as done in Ogre in order to answer the question I posted.

View user profile http://paul.luminos.nl

View previous topic View next topic Back to top  Message [Page 1 of 1]

Post new topic  Reply to topic

Permissions of this forum:
You cannot reply to topics in this forum