# Proper approach to handle transformation matrix and extract its components

Basically I have a Transformation component object with following structure(pseudo):

TransformComponent{
Vec3 position;
Vec3 rotation; //in euler angles
Vec3 scale;
Mat4 worldMatrix; //transformation matrix in world space
Mat4 localMatrix; //transformation matrix relative to parent transform
Mat4 worldToLocal; //Matrix to convert children worldMatrix in localMatrix
TransformComponent parent;

/* calculates worldMatrix using position,rotation & scale.
* Also calculates inverse of worldMatrix and stores it in worldToLocal;
*/
void CalculateWorldMatrix();

}


Then I do some transformations like:

    transform.position = [1,1,1]; //set new position

transform.CalculateWorldMatrix(); //recalculate worldMatrix with new translation coordinates.

//Multiply worldToLocal with worldMatrix in order to get localMatrix.
localMatrix = transform.parent.worldToLocal * transform.worldMatrix;


After that, I have localMatrix with position, rotation etc relative to parent transform. But I can't figure out how to get components(position,eualerAngles,scale) out of localMatrix.

As far as I googled I found some really difficult solutions, which I couldn't understand, and as I'm writing on JavaScript I hope there is a simple solution.

Maybe I am using wrong structure for transform object?
What is the common approach here?

I read that its preferred to use quaternions, but only advance they give is about gimbal lock, at this moment because of simplicity I would like to stick with euler angles if it's possible.