From d9743ba67280140a2e2da7fa89c8b4fc74fcb0a9 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Thu, 6 Sep 2018 17:51:29 -0700 Subject: [PATCH] math for supporting datums --- web/app/brep/geom/pointOnSurface.js | 50 ++++++++++++++++++++++++++++ web/app/cad/model/mdatum.js | 13 ++++++++ web/app/cad/scene/views/datumView.js | 31 +++++++++++++++++ web/app/math/csys.js | 40 ++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 web/app/brep/geom/pointOnSurface.js create mode 100644 web/app/cad/model/mdatum.js create mode 100644 web/app/cad/scene/views/datumView.js create mode 100644 web/app/math/csys.js diff --git a/web/app/brep/geom/pointOnSurface.js b/web/app/brep/geom/pointOnSurface.js new file mode 100644 index 00000000..c2e2c89f --- /dev/null +++ b/web/app/brep/geom/pointOnSurface.js @@ -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]; + } +} \ No newline at end of file diff --git a/web/app/cad/model/mdatum.js b/web/app/cad/model/mdatum.js new file mode 100644 index 00000000..821beaad --- /dev/null +++ b/web/app/cad/model/mdatum.js @@ -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; + } +} \ No newline at end of file diff --git a/web/app/cad/scene/views/datumView.js b/web/app/cad/scene/views/datumView.js new file mode 100644 index 00000000..bc585596 --- /dev/null +++ b/web/app/cad/scene/views/datumView.js @@ -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() { + + } +} \ No newline at end of file diff --git a/web/app/math/csys.js b/web/app/math/csys.js new file mode 100644 index 00000000..57e58962 --- /dev/null +++ b/web/app/math/csys.js @@ -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);