mirror of https://gitee.com/cf-fz/WebCAD.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
57 lines
1.7 KiB
2 years ago
|
import { Euler, Matrix4, Vector3 } from "three";
|
||
|
import { equaln } from "../../src/Geometry/GeUtils";
|
||
|
|
||
|
//证明 EU和旋转矩阵复合的转换
|
||
|
test('Euler', () =>
|
||
|
{
|
||
|
let x = 0.5,
|
||
|
y = 2,
|
||
|
z = 1;
|
||
|
|
||
|
let eu = new Euler(x, y, z, "ZYX");
|
||
|
let mtxEu = new Matrix4().makeRotationFromEuler(eu);//Eu旋转矩阵
|
||
|
|
||
|
let mtxx = new Matrix4().makeRotationX(x);
|
||
|
let mtxy = new Matrix4().makeRotationY(y);
|
||
|
let mtxz = new Matrix4().makeRotationZ(z);
|
||
|
|
||
|
|
||
|
let mtxCom = mtxx.clone().premultiply(mtxy).premultiply(mtxz);//复合矩阵 z * y * x
|
||
|
|
||
|
for (let i = 0; i < mtxEu.elements.length; i++)
|
||
|
expect(equaln(mtxEu.elements[i], mtxCom.elements[i])).toBeTruthy();//证明 z*y*x =Euler("ZYX")
|
||
|
|
||
|
let p = new Vector3(1, 2, 3);
|
||
|
p.clone().applyMatrix4(mtxCom);//?
|
||
|
p.clone().applyMatrix4(mtxx).applyMatrix4(mtxy).applyMatrix4(mtxz);//?
|
||
|
|
||
|
//证明了EU角度不可逆转
|
||
|
new Euler(0, 0, 0, "ZYX").setFromRotationMatrix(mtxCom);//?
|
||
|
|
||
|
//证明了这个不能逆转..
|
||
|
let euT = new Euler(Math.PI / 2, Math.PI / 2, 0, "ZYX");
|
||
|
euT.setFromRotationMatrix(new Matrix4().makeRotationFromEuler(euT));//?
|
||
|
});
|
||
|
|
||
|
//证明 mtxa * mtxb = p.apply(mtxb).apply(mtxa)
|
||
|
test('mtx a*b', () =>
|
||
|
{
|
||
|
let mtx1 = new Matrix4().setPosition(100, 0, 0);
|
||
|
let mtx2 = new Matrix4().makeRotationZ(Math.PI / 2);//旋转90度
|
||
|
let p = new Vector3(100, 0, 0);
|
||
|
mtx1.multiply(mtx2);
|
||
|
p.applyMatrix4(mtx1);
|
||
|
p; //?
|
||
|
});
|
||
|
|
||
|
|
||
|
test('mtx a*b2', () =>
|
||
|
{
|
||
|
let mtx1 = new Matrix4().setPosition(100, 0, 0);
|
||
|
let mtx2 = new Matrix4().makeRotationZ(Math.PI / 2);
|
||
|
mtx1.premultiply(mtx2);
|
||
|
let p = new Vector3(100, 0, 0);
|
||
|
p.applyMatrix4(mtx1);
|
||
|
p; //?
|
||
|
});
|