Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Useless Work :'( RIP
- interface TestData {
- transformation: {
- Tx: number;
- Ty: number;
- Tz: number;
- angle: number; //radian
- Vx: number;
- Vy: number;
- Vz: number;
- S: number;
- };
- matrice_4x4: number[];
- echelle_3x1: number[];
- }
- function TransformationVersMatriceDigiTwin(tr: TestData): TestData {
- //quaternion
- var w = 0;
- var x = 0;
- var y = 0;
- var z = 0;
- if (tr.transformation.angle != 0 || (tr.transformation.Vx != 0 && tr.transformation.Vy != 0 && tr.transformation.Vz != 0)) {
- //cosinus directionnels
- var V_norme = Math.sqrt(Math.pow(tr.transformation.Vx, 2) + Math.pow(tr.transformation.Vy, 2) + Math.pow(tr.transformation.Vz, 2));
- var cosX = tr.transformation.Vx / V_norme;
- var cosY = tr.transformation.Vy / V_norme;
- var cosZ = tr.transformation.Vz / V_norme;
- //quaternion : q = a +ib + jc + kd
- var sinA = Math.sin(tr.transformation.angle / 2);
- w = Math.cos(tr.transformation.angle / 2);
- x = sinA * cosX;
- y = sinA * cosY;
- z = sinA * cosZ;
- //quaternion normalisé
- var q_norme = Math.sqrt(Math.pow(w, 2) + Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
- w /= q_norme;
- x /= q_norme;
- y /= q_norme;
- z /= q_norme;
- }
- //construction de la matrice
- var matrice_4x4: number[] = [
- Math.pow(w, 2) + Math.pow(x, 2) - Math.pow(y, 2) - Math.pow(z, 2),
- 2 * x * y - 2 * w * z,
- 2 * x * z + 2 * w * y,
- 0,
- 2 * x * y + 2 * w * z,
- Math.pow(w, 2) - Math.pow(x, 2) + Math.pow(y, 2) - Math.pow(z, 2),
- 2 * y * z - 2 * w * x,
- 0,
- 2 * x * z - 2 * w * y,
- 2 * y * z + 2 * w * x,
- Math.pow(w, 2) - Math.pow(x, 2) - Math.pow(y, 2) + Math.pow(z, 2),
- 0,
- tr.transformation.Tx, tr.transformation.Ty, tr.transformation.Tz, 1];
- //échelle
- var echelle_3x1: number[] = [tr.transformation.S, tr.transformation.S, tr.transformation.S];
- return { transformation: tr.transformation, matrice_4x4, echelle_3x1 };
- }
- function MatriceDigiTwinVersTransformation(mtr: TestData): TestData {
- //translation
- var Tx = mtr.matrice_4x4[12];
- var Ty = mtr.matrice_4x4[13];
- var Tz = mtr.matrice_4x4[14];
- //composants de la matrice de rotation
- var quu = mtr.matrice_4x4[0];
- var quv = mtr.matrice_4x4[1];
- var quw = mtr.matrice_4x4[2];
- var qvu = mtr.matrice_4x4[4];
- var qvv = mtr.matrice_4x4[5];
- var qvw = mtr.matrice_4x4[6];
- var qwu = mtr.matrice_4x4[8];
- var qwv = mtr.matrice_4x4[9];
- var qww = mtr.matrice_4x4[10];
- //reconstruction du quaternion
- var w = 1 / 2 * Math.sqrt(1 + quu + qvv + qww);
- var x = 1 / (4 * w) * (qwv - qvw);
- var y = 1 / (4 * w) * (quw - qwu);
- var z = 1 / (4 * w) * (qvu - quv);
- //calcul de l'angle et de l'axe de rotation
- var angle = 0; var Vx = 0; var Vy = 0; var Vz = 0;
- var xyz_norme = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
- if (xyz_norme != 0) {
- angle = 2 * Math.atan2(xyz_norme, w);
- Vx = x / xyz_norme;
- Vy = y / xyz_norme;
- Vz = z / xyz_norme;
- }
- //échelle
- var S = (mtr.echelle_3x1[0] + mtr.echelle_3x1[1] + mtr.echelle_3x1[2]) / 3;
- return { transformation: { Tx, Ty, Tz, angle, Vx, Vy, Vz, S }, matrice_4x4: mtr.matrice_4x4, echelle_3x1: mtr.echelle_3x1 }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement