Jump to content

Matrix decompose scaling bug


Recommended Posts


The matrix decompose returns wrong scale value when scale is negative



Here scling.z is being set to -2, decompose returns +2

I think the bug got introduced by this change


Fixed matrix decomposition with negative scaling


Link to comment
Share on other sites


I am not sure how to fix it.
Don't think the previous solution would have worked either.
That relied on the signs of each co-ordinates of the unit vectors.
I think that would only be reliable if the rotation was zero.

We might also have a similar issue with getRotationMatrixToRef(). 

 Won't m[3],m[7],m[11] always be zero?

Anyway It is an interesting problem and I will keep looking into it.


Link to comment
Share on other sites

I don't think decompose is wrong. Once a scale is composed into a matrix, the information on which component is negative is lost as there are multiple ways to represent the same transformation.

If you change your playground to output all the values, you'll notice the y component of the scale is negative and note that rotation is not identity.


Link to comment
Share on other sites

The more I think about it the more I believe you are right about "Once a scale is composed into a matrix, the information on which component is negative is lost ".
It seems you can find that one of the component is negative but not which one

and maybe just knowing that one of the component is negative is good enough to figure out the correct rotation.
what about getRotationMatrixToRef()? needs to be corrected?


Link to comment
Share on other sites

The math are correct but having a negative scale is something we cannot detect as the extracted scale is always positive (we consider it as a vector length)

I can easily fix the computation with : https://www.babylonjs-playground.com/#ZXZI83#4

But it is a trick as I switch scale.z because I know that initial scling was negative on z


I see no solution to this problem

Link to comment
Share on other sites



23 hours ago, Deltakosh said:

I see no solution to this problem

 Me too :(

it seems that based on just the matrix the only conclusion one can  definitely arrive at is
i) one scale is -negative  or all scales are negative  or
ii) one scale is positive  or all scales are positive
but not which scale exactly.

This would be based on taking cross product of two vectors and  then dot product with the third vector
if (Vector3.Cross(ux,uy).Dot(uz))<0  then one scale is negative   or all scales are negative   
else  one  scale is positive or all scales are positive

Maybe mathematically impossible to determine the sign of the original  scale?

If that is the  case then should  the user provide the information ? as optional params?


where signX,signY,signZ would be 1 or -1 


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...