mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-09 18:02:50 +01:00
66 lines
1.3 KiB
JavaScript
66 lines
1.3 KiB
JavaScript
import {AXIS, Matrix3, ORIGIN} from './l3space';
|
|
|
|
export default class CSys {
|
|
|
|
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 outTransformation() {
|
|
if (!this._outTr) {
|
|
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;
|
|
this._outTr = mx;
|
|
}
|
|
return this._outTr;
|
|
}
|
|
|
|
get inTransformation() {
|
|
if (!this._inTr) {
|
|
this._inTr = this.outTransformation.invert();
|
|
}
|
|
return this._inTr;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
CSys.ORIGIN = CSys.origin();
|
|
|
|
Object.freeze(CSys.ORIGIN.origin);
|
|
Object.freeze(CSys.ORIGIN.x);
|
|
Object.freeze(CSys.ORIGIN.y);
|
|
Object.freeze(CSys.ORIGIN.z);
|