# Need help supporting negative values when extracting scale from 4x4 Transform matrix

I’ve been able to decompose a matrix into transform and rotation is easy enough, but I can’t seem to wrap my head around how I could determine whether some of the scale values are positive or negative.
The solution I have at the moment is as follows:

``````Matrix4x4 t;

scale = new Vector3(Mathf.Sqrt(t.m00 * t.m00 + t.m10 * t.m10 + t.m20 * t.m20),
Mathf.Sqrt(t.m01 * t.m01 + t.m11 * t.m11 + t.m21 * t.m21),
Mathf.Sqrt(t.m02 * t.m02 + t.m12 * t.m12 + t.m22 * t.m22));
``````

All the scale values are output as positive regardless of their original value.

Does anyone know a solution to this problem? Perhaps some code I could look at or a particular formula?

http://www.robertblum.com/articles/2005/02/14/decomposing-matrices

Hello, I’m looking for a solution for this too, and found this article. According to this article, you can only determine if one of the three scale axis is negative by calculating the determinant of m00-m22(rotation matrix) and check its sign.
Unfortunately you can not determine two, three axis or which axis is negative exactly, because in each case they’re mathematically the same and may be hidden by rotation, like (-1,-1,1) scale is the same as rotation(0,0,180).