mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 08:25:19 +01:00
87 lines
1.8 KiB
TypeScript
87 lines
1.8 KiB
TypeScript
import {AXIS, Matrix3, ORIGIN} from './l3space';
|
|
import Vector from "math/vector";
|
|
|
|
export default class CSys {
|
|
|
|
static ORIGIN: CSys;
|
|
|
|
origin: Vector;
|
|
x: Vector;
|
|
y: Vector;
|
|
z: Vector;
|
|
private _outTr: Matrix3;
|
|
private _inTr: Matrix3;
|
|
|
|
static fromNormalAndDir(origin, normal, dir) {
|
|
return new CSys(origin, dir, normal.cross(dir), normal)
|
|
}
|
|
|
|
static origin() {
|
|
return new CSys(ORIGIN.copy(), AXIS.X.copy(), AXIS.Y.copy(), AXIS.Z.copy());
|
|
}
|
|
|
|
constructor(origin, x, y, z) {
|
|
this.origin = origin;
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
}
|
|
|
|
w() {
|
|
return this.z.dot(this.origin);
|
|
}
|
|
|
|
get outTransformation3x3() {
|
|
return new Matrix3().setBasisAxises(this.x, this.y, this.z);
|
|
}
|
|
|
|
get outTransformation() {
|
|
const mx = new Matrix3().setBasisAxises(this.x, this.y, this.z);
|
|
mx.tx = this.origin.x;
|
|
mx.ty = this.origin.y;
|
|
mx.tz = this.origin.z;
|
|
return mx;
|
|
}
|
|
|
|
get inTransformation3x3() {
|
|
return this.outTransformation3x3.invert();
|
|
}
|
|
|
|
get inTransformation() {
|
|
return this.outTransformation.invert();
|
|
}
|
|
|
|
copy(csys) {
|
|
this.origin.setV(csys.origin);
|
|
this.x.setV(csys.x);
|
|
this.y.setV(csys.y);
|
|
this.z.setV(csys.z);
|
|
return this;
|
|
}
|
|
|
|
clone() {
|
|
return new CSys(this.origin.copy(), this.x.copy(), this.y.copy(), this.z.copy());
|
|
}
|
|
|
|
move(x, y, z) {
|
|
this.origin.set(x, y, z);
|
|
return this;
|
|
}
|
|
|
|
invert() {
|
|
const tr = this.inTransformation;
|
|
return new CSys(
|
|
new Vector(tr.tx, tr.ty, tr.tz),
|
|
new Vector(tr.mxx, tr.myx, tr.mzx),
|
|
new Vector(tr.mxy, tr.myy, tr.mzy),
|
|
new Vector(tr.mxz, tr.myz, tr.mzz)
|
|
);
|
|
}
|
|
}
|
|
|
|
CSys.ORIGIN = CSys.origin();
|
|
|
|
Object.freeze(CSys.ORIGIN.origin);
|
|
Object.freeze(CSys.ORIGIN.x);
|
|
Object.freeze(CSys.ORIGIN.y);
|
|
Object.freeze(CSys.ORIGIN.z);
|