mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-08 01:13:27 +01:00
math for supporting datums
This commit is contained in:
parent
0efeee3ea6
commit
d9743ba672
4 changed files with 134 additions and 0 deletions
50
web/app/brep/geom/pointOnSurface.js
Normal file
50
web/app/brep/geom/pointOnSurface.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
export class PointOnSurface {
|
||||
|
||||
static from(surface, u, v) {
|
||||
return new PointOnSurface(surface, [u, v], undefined);
|
||||
}
|
||||
|
||||
static fromUV(surface, u, v) {
|
||||
return new PointOnSurface(surface, [u, v], undefined);
|
||||
}
|
||||
|
||||
constructor(surface, uv, xyz) {
|
||||
this.surface = surface;
|
||||
this._uv = uv;
|
||||
this._xyz = xyz;
|
||||
}
|
||||
|
||||
get uv() {
|
||||
if (this._uv) {
|
||||
this._uv = this.surface.param(this._xyz);
|
||||
}
|
||||
return this._uv;
|
||||
}
|
||||
|
||||
get xyz() {
|
||||
if (this._xyz) {
|
||||
this._xyz = this.surface.point(this._uv);
|
||||
}
|
||||
return this._xyz;
|
||||
}
|
||||
|
||||
get u() {
|
||||
return this.uv[0];
|
||||
}
|
||||
|
||||
get v() {
|
||||
return this.uv[1];
|
||||
}
|
||||
|
||||
get x() {
|
||||
return this.xyz[0];
|
||||
}
|
||||
|
||||
get y() {
|
||||
return this.xyz[1];
|
||||
}
|
||||
|
||||
get z() {
|
||||
return this.xyz[2];
|
||||
}
|
||||
}
|
||||
13
web/app/cad/model/mdatum.js
Normal file
13
web/app/cad/model/mdatum.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import {MObject} from './mobject';
|
||||
|
||||
export class MDatum extends MObject {
|
||||
|
||||
static TYPE = 'datum';
|
||||
static ID_COUNTER = 0;
|
||||
|
||||
constructor(csys) {
|
||||
super();
|
||||
this.id = 'D:' + (MDatum.ID_COUNTER++);
|
||||
this.csys = csys;
|
||||
}
|
||||
}
|
||||
31
web/app/cad/scene/views/datumView.js
Normal file
31
web/app/cad/scene/views/datumView.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import {View} from './view';
|
||||
import * as SceneGraph from '../../../../../modules/scene/sceneGraph';
|
||||
import {createArrow} from '../../../../../modules/scene/objects/auxiliary';
|
||||
import {moveObject3D} from '../../../../../modules/scene/objects/transform';
|
||||
import {AXIS} from '../../../math/l3space';
|
||||
|
||||
export default class DatumView extends View {
|
||||
|
||||
constructor(edge) {
|
||||
super(edge);
|
||||
this.rootGroup = SceneGraph.createGroup();
|
||||
}
|
||||
|
||||
setUpAxises() {
|
||||
let arrowLength = 100;
|
||||
let createAxisArrow = createArrow.bind(null, arrowLength, 5, 2);
|
||||
let addAxis = (axis, color) => {
|
||||
let arrow = createAxisArrow(axis, color, 0.2);
|
||||
moveObject3D(arrow, axis.scale(-arrowLength * 0.5));
|
||||
SceneGraph.addToGroup(this.auxGroup, arrow);
|
||||
};
|
||||
addAxis(AXIS.X, 0xFF0000);
|
||||
addAxis(AXIS.Y, 0x00FF00);
|
||||
addAxis(AXIS.Z, 0x0000FF);
|
||||
}
|
||||
|
||||
|
||||
dispose() {
|
||||
|
||||
}
|
||||
}
|
||||
40
web/app/math/csys.js
Normal file
40
web/app/math/csys.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import {AXIS, Matrix3, ORIGIN} from './l3space';
|
||||
|
||||
export default class CSys {
|
||||
|
||||
static fromNormalAndDir(origin, normal, dir) {
|
||||
return new CSys(origin, dir, normal.cross(dir), normal)
|
||||
}
|
||||
|
||||
constructor(origin, x, y, z) {
|
||||
this.origin = origin;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
get inTransformation() {
|
||||
if (!this._inTr) {
|
||||
const basis = new Matrix3().setBasis([this.x, this.y, this.z]);
|
||||
const translate = new Matrix3();
|
||||
translate.tx = this.origin.x;
|
||||
translate.ty = this.origin.y;
|
||||
translate.tz = this.origin.z;
|
||||
this._inTr = basis.combine(translate);
|
||||
}
|
||||
return this._inTr;
|
||||
}
|
||||
|
||||
get outTransformation() {
|
||||
if (!this._outTr) {
|
||||
this._outTr = this.inTransformation().invert();
|
||||
}
|
||||
return this._outTr;
|
||||
}
|
||||
|
||||
copy() {
|
||||
return CSys(this.origin, this.x, this.y, this.z);
|
||||
}
|
||||
}
|
||||
|
||||
CSys.ORIGIN = new CSys(ORIGIN, AXIS.X, AXIS.Y, AXIS.Z);
|
||||
Loading…
Reference in a new issue