Convert Axis Angle to 4x4 homogeneous matrix?

In summary, the author used a series of mathematical calculations to convert the axis angle representation of a rotation to a 4x4 homogeneous matrix. This involved converting the axis angle to a quaternion first, using the sin and cos functions, and then using those values to fill in the elements of the matrix. The author also provided a link to a website with more information on the conversion process.
  • #1
sarah22
26
0
I'm stuck on how did the author managed to convert the axis angle to a 4x4 homogenous matrix.

Here's the code below. The bolded ones are the one I'm struggling at right now.

void glQuaternion::CreateMatrix(GLfloat *pMatrix)
{
// Make sure the matrix has allocated memory to store the rotation data
if(!pMatrix) return;

// First row
pMatrix[ 0] = 1.0f - 2.0f * ( m_y * m_y + m_z * m_z );
pMatrix[ 1] = 2.0f * (m_x * m_y + m_z * m_w);
pMatrix[ 2] = 2.0f * (m_x * m_z - m_y * m_w);
pMatrix[ 3] = 0.0f;

// Second row
pMatrix[ 4] = 2.0f * ( m_x * m_y - m_z * m_w );
pMatrix[ 5] = 1.0f - 2.0f * ( m_x * m_x + m_z * m_z );
pMatrix[ 6] = 2.0f * (m_z * m_y + m_x * m_w );
pMatrix[ 7] = 0.0f;

// Third row
pMatrix[ 8] = 2.0f * ( m_x * m_z + m_y * m_w );
pMatrix[ 9] = 2.0f * ( m_y * m_z - m_x * m_w );
pMatrix[10] = 1.0f - 2.0f * ( m_x * m_x + m_y * m_y );
pMatrix[11] = 0.0f;

// Fourth row
pMatrix[12] = 0;
pMatrix[13] = 0;
pMatrix[14] = 0;
pMatrix[15] = 1.0f;

// Now pMatrix[] is a 4x4 homogeneous matrix that can be applied to an OpenGL Matrix
}

Before he use the code above. He converted the axis angle to quaternion first which is the one below. I somehow managed to understand this one though. (http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm")

void glQuaternion::CreateFromAxisAngle(GLfloat x, GLfloat y, GLfloat z, GLfloat degrees)
{
// First we want to convert the degrees to radians
// since the angle is assumed to be in radians
GLfloat angle = GLfloat((degrees / 180.0f) * PI);

// Here we calculate the sin( theta / 2) once for optimization
GLfloat result = (GLfloat)sin( angle / 2.0f );

// Calcualte the w value by cos( theta / 2 )
m_w = (GLfloat)cos( angle / 2.0f );

// Calculate the x, y and z of the quaternion
m_x = GLfloat(x * result);
m_y = GLfloat(y * result);
m_z = GLfloat(z * result);
}

So my question is, how did he arrived to that formula (the bold one on the first code) ? If possible you can give me some links on how did he get that?

I'm looking all over the google but didn't get one. Maybe my tags were wrong.

Source for the code above: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Quaternion_Camera_Class

Thank you
Sarah
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
nevermind. I got it.
 

Related to Convert Axis Angle to 4x4 homogeneous matrix?

1. What is an axis angle representation?

An axis angle representation is a way to describe the orientation of an object in three-dimensional space. It consists of an axis, which is a vector that points in the direction of the rotation axis, and an angle, which represents the amount of rotation around that axis.

2. Why convert axis angle to a 4x4 homogeneous matrix?

A 4x4 homogeneous matrix is a mathematical representation of a transformation in three-dimensional space. Converting an axis angle to a 4x4 homogeneous matrix allows for easier manipulation and calculation of rotations and transformations in computer graphics and robotics applications.

3. How do you convert axis angle to a 4x4 homogeneous matrix?

To convert an axis angle to a 4x4 homogeneous matrix, you can use the following formula:

M = cos(angle) * I + (1 - cos(angle)) * a * a^T + sin(angle) * [a]x

Where M is the resulting 4x4 homogeneous matrix, angle is the angle of rotation, a is the unit vector representing the rotation axis, I is the identity matrix, and [a]x is the skew-symmetric matrix of a.

4. What is the purpose of the skew-symmetric matrix in the conversion process?

The skew-symmetric matrix, also known as the cross product matrix, is used to represent the vector cross product operation in the conversion process. It allows for the calculation of rotation around an arbitrary axis, rather than being limited to rotation around the x, y, or z-axis.

5. Can you convert a 4x4 homogeneous matrix back to an axis angle representation?

Yes, it is possible to convert a 4x4 homogeneous matrix back to an axis angle representation. This can be done by extracting the rotation axis and angle from the matrix using mathematical operations such as the dot product and inverse trigonometric functions.

Similar threads

Replies
2
Views
2K
Replies
1
Views
2K
Back
Top