Jump to content

  • Log In with Google      Sign In   
  • Create Account


[Answered] Matrix create from XYZ rotation: scale problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 thecheeselover   Members   -  Reputation: 325

Like
0Likes
Like

Posted 06 October 2012 - 08:00 PM

Hi

I've been coding my own math library and I got a bug when I create a Matrix from a rotation across the X, Y and Z axises. The bug is that it also scales my vectors. I know it might be hard to understand my code, but you are my only hope left (I checked and checked again my code a lot of times) so here's my code:

static Matrix4x4<T> CreateFromRotationXYZ_S(const T &radiansX, const T &radiansY, const T &radiansZ)
	{
		Matrix4x4<T> result;
		result.m11 = cos(radiansY) * cos(radiansZ);
		result.m12 = cos(radiansY) * sin(radiansZ);
		result.m13 = sin(radiansY);
		result.m14 = 0;
		result.m21 = sin(radiansX) * -sin(radiansY) * cos(radiansZ) + cos(radiansX) * -sin(radiansZ) + sin(radiansX) * cos(radiansY);
		result.m22 = sin(radiansX) * -sin(radiansY) * sin(radiansZ) + cos(radiansX) * cos(radiansZ) + sin(radiansX) * cos(radiansX);
		result.m23 = sin(radiansX) * cos(radiansY);
		result.m24 = 0;
		result.m31 = cos(radiansX) * -sin(radiansY) * cos(radiansZ) + sin(radiansX) * sin(radiansZ);
		result.m32 = cos(radiansX) * -sin(radiansY) * sin(radiansZ) + -sin(radiansX) * cos(radiansZ);
		result.m33 = cos(radiansX) * cos(radiansY);
		result.m34 = 0;
		result.m41 = 0;
		result.m42 = 0;
		result.m43 = 0;
		result.m44 = 1;
		return result;
	}

Thank you Posted Image
Hide yo cheese! Hide yo wife!

Sponsor:

#2 xissburg   Members   -  Reputation: 200

Like
0Likes
Like

Posted 06 October 2012 - 09:16 PM

Ouch. You better create a simple rotation matrix for each axis and multiply(compose) all three to obtain the final rotation matrix.
.

#3 haegarr   Crossbones+   -  Reputation: 3973

Like
2Likes
Like

Posted 07 October 2012 - 03:05 AM

Mistakes are at least in the formulas of m21 and m22 (both showing 3 summands), because their format has to be the same as those of m31 and m32 (both showing 2 summands).

As a hint: The length of each column vector and each row vector in a pure rotation matrix is 1. If the length differs from 1 then scaling will occur.

Edited by haegarr, 07 October 2012 - 03:07 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS