Jump to content
  • Advertisement
Sign in to follow this  
giugio

adjust matrixes and correct axes

This topic is 2462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello.
I'm creating an ifc importer.
I'm creating some simple beam with rotation about X , about Y and about Z.
These are the matrixes that i get:

1)Rotation about Z
0.8|0.5|0.0
0.0|0.0|1.0
-0.5|0.8|0.0
i know that the real rotation about Z is :
0.8|0.5|0.0
-0.5|0.8|0.0
0.0|0.0|1.0

then i must swap the axis y with z


1)Rotation about X
0.0|0.8|0.5
1.0|0.0|0.0
0.0|-0.5|0.8

i know that the real rotation about X is :
1.0|0.0|0.0
0.0|0.8|0.5
0.0|0.5|0.8

then i must swap the axis y with x


1)Rotation about Y
0.8|0.0|0.5
0.0|1.0|0.0
0.8|0.0|0.8

that is a correct Y rotation matrix.

Exist a matrix that multiplied for the Z matrix rotation swap the y axis with the z axis and
that multiplied for the X matrix rotation swap the y axis and the x axis?
thanks.

another thing:
i'm working with these matrixes for extract the rotation angles about x,y and z , the function that extract the angle is this :


void C3DMatrixIfc::ExtractAxisAngle (C3DVectorIfc& axis, double& angle)
{
// Let (x,y,z) be the unit-length axis and let A be an angle of rotation.
// The rotation matrix is R = I + sin(A)*P + (1-cos(A))*P^2 where
// I is the identity and
//
// +- -+
// P = | 0 -z +y |
// | +z 0 -x |
// | -y +x 0 |
// +- -+
//
// If A > 0, R represents a counterclockwise rotation about the axis in
// the sense of looking from the tip of the axis vector towards the
// origin. Some algebra will show that
//
// cos(A) = (trace(R)-1)/2 and R - R^t = 2*sin(A)*P
//
// In the event that A = pi, R-R^t = 0 which prevents us from extracting
// the axis through P. Instead note that R = I+2*P^2 when A = pi, so
// P^2 = (R-I)/2. The diagonal entries of P^2 are x^2-1, y^2-1, and
// z^2-1. We can solve these for axis (x,y,z). Because the angle is pi,
// it does not matter which sign you choose on the square roots.

double trace = m_X.x + m_Y.y + m_Z.z;
double cs = (0.5)*(trace - 1);
angle = ACos(cs); // in [0,PI]


if (angle > 0)
{
if (angle < PI)
{
axis.x = m_Z.y - m_Y.z;
axis.y = m_X.z - m_Z.x;
axis.z = m_Y.x - m_X.y;
axis.Normalize();
}
else
{
// angle is PI
double halfInverse;
if (m_X.x >= m_Y.y)
{
// r00 >= r11
if (m_X.x >= m_Z.z)
{
// r00 is maximum diagonal term
axis.x = (0.5)*sqrtf(1 + m_X.x - m_Y.y - m_Z.z);
halfInverse = (0.5)/axis.x;
axis.y = halfInverse*m_X.y;
axis.z = halfInverse*m_X.z;
}
else
{
// r22 is maximum diagonal term
axis.z = (0.5)*sqrtf(1 + m_Z.z - m_X.x - m_Y.y);
halfInverse = (0.5)/axis.z;
axis.x = halfInverse*m_X.z;
axis.y = halfInverse*m_Y.z;
}
}
else
{
// r11 > r00
if (m_Y.y >= m_Z.z)
{
// r11 is maximum diagonal term
axis.y = (0.5)* sqrtf(1+ m_Y.y - m_X.x - m_Z.z);
halfInverse = (0.5)/axis.y;
axis.x = halfInverse*m_X.y;
axis.z = halfInverse*m_Y.z;
}
else
{
// r22 is maximum diagonal term
axis.z = (0.5)*sqrtf(1+ m_Z.z - m_X.x - m_Y.y);
halfInverse = (0.5)/axis.z;
axis.x = halfInverse*m_X.z;
axis.y = halfInverse*m_Y.z;
}
}
}
}
else
{
// The angle is 0 and the matrix is the identity. Any axis will
// work, so just use the x-axis.
axis.x = 1;
axis.y = 0;
axis.z = 0;
}
}


extracted from wild magic 5 engine of geometrictools.

Share this post


Link to post
Share on other sites
Advertisement
Hi!


Exist a matrix that multiplied for the Z matrix rotation swap the y axis with the z axis and
that multiplied for the X matrix rotation swap the y axis and the x axis?

Jep, a permutation matrix will do.

P is a matrix that exchanges y and z. Use multiplication from left for row exchange.
[Formula]P=\begin{pmatrix}1 & 0 & 0\\0 & 0 & 1\\0 & 1 & 0\end{pmatrix},\hat{A}=PA[/Formula]

Q is a matrix that exchanges x and y. Use multiplication from left for row exchange.
[Formula]Q=\begin{pmatrix}0 & 1 & 0\\1 & 0 & 0\\0 & 0 & 1\end{pmatrix},\hat{B}=QB[/Formula]


another thing:
i'm working with these matrixes for extract the rotation angles about x,y and z , the function that extract the angle is this :


void C3DMatrixIfc::ExtractAxisAngle (C3DVectorIfc& axis, double& angle)
{
// Let (x,y,z) be the unit-length axis and let A be an angle of rotation.
// The rotation matrix is R = I + sin(A)*P + (1-cos(A))*P^2 where
// I is the identity and
//
// +- -+
// P = | 0 -z +y |
// | +z 0 -x |
// | -y +x 0 |
// +- -+
//
// If A > 0, R represents a counterclockwise rotation about the axis in
// the sense of looking from the tip of the axis vector towards the
// origin. Some algebra will show that
//
// cos(A) = (trace(R)-1)/2 and R - R^t = 2*sin(A)*P
//
// In the event that A = pi, R-R^t = 0 which prevents us from extracting
// the axis through P. Instead note that R = I+2*P^2 when A = pi, so
// P^2 = (R-I)/2. The diagonal entries of P^2 are x^2-1, y^2-1, and
// z^2-1. We can solve these for axis (x,y,z). Because the angle is pi,
// it does not matter which sign you choose on the square roots.

double trace = m_X.x + m_Y.y + m_Z.z;
double cs = (0.5)*(trace - 1);
angle = ACos(cs); // in [0,PI]


if (angle > 0)
{
if (angle < PI)
{
axis.x = m_Z.y - m_Y.z;
axis.y = m_X.z - m_Z.x;
axis.z = m_Y.x - m_X.y;
axis.Normalize();
}
else
{
// angle is PI
double halfInverse;
if (m_X.x >= m_Y.y)
{
// r00 >= r11
if (m_X.x >= m_Z.z)
{
// r00 is maximum diagonal term
axis.x = (0.5)*sqrtf(1 + m_X.x - m_Y.y - m_Z.z);
halfInverse = (0.5)/axis.x;
axis.y = halfInverse*m_X.y;
axis.z = halfInverse*m_X.z;
}
else
{
// r22 is maximum diagonal term
axis.z = (0.5)*sqrtf(1 + m_Z.z - m_X.x - m_Y.y);
halfInverse = (0.5)/axis.z;
axis.x = halfInverse*m_X.z;
axis.y = halfInverse*m_Y.z;
}
}
else
{
// r11 > r00
if (m_Y.y >= m_Z.z)
{
// r11 is maximum diagonal term
axis.y = (0.5)* sqrtf(1+ m_Y.y - m_X.x - m_Z.z);
halfInverse = (0.5)/axis.y;
axis.x = halfInverse*m_X.y;
axis.z = halfInverse*m_Y.z;
}
else
{
// r22 is maximum diagonal term
axis.z = (0.5)*sqrtf(1+ m_Z.z - m_X.x - m_Y.y);
halfInverse = (0.5)/axis.z;
axis.x = halfInverse*m_X.z;
axis.y = halfInverse*m_Y.z;
}
}
}
}
else
{
// The angle is 0 and the matrix is the identity. Any axis will
// work, so just use the x-axis.
axis.x = 1;
axis.y = 0;
axis.z = 0;
}
}


extracted from wild magic 5 engine of geometrictools.

Alright, what’s your question to that?

Cheers!

Share this post


Link to post
Share on other sites
very thanks.
I have reported my sample matrixes.
For each matrix i have also a relative matrix that for these matrixes is identity(but can change for other models).
I must swap a column or two in my matrixes for a difference in the axis of my program and the .ifc axis.
If i swap one or two axis i also swap axis in the identity matrix, then the identity matrix(that for this model is identity )can become a Permutation matrix that multiplied for the sample matrixes.....

I try and try , but i can't find a solution that transform all the sample matrixes of the model in a correct rotation matrixes, after the swap of axes and the multiply for the permutation matrix(that before the swap is an identity).
Is possible create a linear system with matrixes?
for example
A * PERMUTATIONMATRIX = XMATRIX
B * PERMUTATIONMATRIX = YMATRIX
C * PERMUTATIONMATRIX = ZMATRIX

Where
XMATRIX is a correct matrix rotation about x axis,
YMATRIX is a correct matrix rotation about y axis,
ZMATRIX is a correct matrix rotation about z axis ,

I know A,B and C , and i don't know XMATRIX,YMATRIX and ZMATRIX , but i know that are correct rotation matrixes ,and the PERMUTATIONMATRIX is the same in all the three equations.

I'm Sorry for my inexperience , but i wish find a system for know wich of the three axis i must exchange for get a permutation matrix that transform the 3 sample matrixes in correct rotation matrixes.
The reltive matrixes that for now are identity can become a permutation matrix when i swap one or more axis.
Thanks.

Share this post


Link to post
Share on other sites
Hi,

I’m sorry, but I have trouble to understand your question. Could you rephrase it a little, please?
If I understand correctly, you have given:

  • a rotation matrix that’s rows are somehow exchanged
  • an additional relative transformation for each rotation matrix.

    You want:

    • to fix the order of the columns (Btw, last time you said rows. This actually matters, so what is it?)
    • find the complete transformation (all transformations multiplied together)

      My question is: What does the relative transformation do? Is it some sort of translation to a pivot point to rotate around? Or is it a transformation applied after the rotation?

      You want to find one single permutation matrix that fixes all your rotation matrices, regardless of which rows/columns are exchanged, right? That sounds impossible. Why not looking at the position of the 1 in the middle row and decide based on that, which permutation to apply?


      The relative matrices that for now are identity can become a permutation matrix when i swap one or more axis.

      You don't have to apply the permutation matrix to the relative matrix. It should be fine, I think.
      Like this perhaps:
      Complete = Relative * Permutation * Rotation // Here the Relative matrix would be a transformation applied after the rotation. (read from right to left.)

      Cheers!

Share this post


Link to post
Share on other sites
I tried this approach

I have a matrix that rotates a set of points on a plane around a direction that is the nomal of the plane.
my problem is to find how these point are rotated around the normal and find an angle of rotation of these points about the normal direction.
These points are a profile.
I tryed to do this with creating of a matrix that transform my basic points in a tangent space, like the bump mapping .
Then i calculated the tangent,the normal and the binormal and i have create a matrix like:

T;T;T
B;B;B
N;N:N

N is calculated with the cross product of two edge of the profile(i use tree point of the profile that are not in line)
T is N rotated of 90 °(degree) swap the z with y and negate y.
B is the cross product of T and N.



This matrix transforms in a tangent space.
But In tangent space how i can calculate the angle about the normal direction of the plane?
result of the matrix rotation?

mine is a sound approach?
because i can't find the correct angle!

thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!