How to obtain the transformation matrix from three dimensions spaces basis using javascript?

201 views Asked by At

Having two Three dimensional spaces basis, I need to find the transformation matrix so I can convert points between two coordinate systems. I'm using Three js Vector3 as basis for the spaces.

Space A basis:
X - THREE.Vector3 {x: 0, y: -2.4797891148376707, z: 0.054067921976497235} 
Y - THREE.Vector3 {x: 0.0625, y: 0.041246288882594406, z: 1.8917334800284853} 
Z - THREE.Vector3 {x: -5.101850904697792, y: 0.003673384160379493, z: 0.16847731006724959}

Space B basis:
X - THREE.Vector3 {x: 0, y: 29.828016820959952, z: -0.23079947575435433}
Y - THREE.Vector3 {x: 0.75, y: 0.1846261135594407, z: 23.86067300560442}
Z - THREE.Vector3 {x: -61.400324372163844, y: 0.014932539676718379, z: 1.9298485977969317}

Couldn't find any method for obtaining the Transformation matrix for this case. Would be great to find a way to calculate this programatically based on two Spaces basis.

1

There are 1 answers

0
Mugen87 On BEST ANSWER

Use Matrix4.makeBasis() to setup two matrices. The method accepts three vectors for defining the basis of a 4x4 matrix. If you now need a matrix that maps from basis A to B, do this:

const m = new THREE.Matrix4();
m.multiplyMatrices( b, a.transpose() );