Skip to content
This repository was archived by the owner on Jul 17, 2026. It is now read-only.
This repository was archived by the owner on Jul 17, 2026. It is now read-only.

Decomposing a Matrix4 does not result in the same scale as its composition. #240

Description

@danielljunior

To replicate the error do the following:
Create a random Vector3 for position.
Create a random Vector3 for scale.
Create a random Quaternion for rotation.

Compose a Matrix4 with the above inputs.
Decompose this same matrix to other scale, rotation and position objects, for comparison.
The position and rotation match, but the scale - except for x:1.0, y:1.0, z:1.0 - does not match.

The following is the code I used in my test:

test(
    'Decomposing a Matrix4 results in roughly the same'
    'translation, rotation and scale as its composition',
    (){

        for( int i=0; i<128; ++i ){
            setVector3ToRandom( position, RNG );
            setVector3ToRandom( scale, RNG );
            rotation.setRandom( RNG );

            Matrix4 transform = Matrix4.compose(
                position, rotation, scale
            );

            transform.decompose(
                decomposedPosition,
                decomposedRotation,
                decomposedScale
            );

            expect(
                decomposedPosition,
                equals( position )
            );

            expect(
                decomposedRotation
                    .absoluteError( rotation ),
                lessThan( EPSILON )
            );

            expect(
                decomposedScale.absoluteError( scale ),
                lessThan( EPSILON )
            );
        }

    }
);

The absolute error on the scale is usually huge, the smallest error I got was aound 700.0. The setVector3ToRandom() method generates values from -1024.0 to 1024.0 on each axys.

Edit:
The problem only happens when negative values are used in the scale vector of the composition. Is there reason for that or is it really a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions