From 02bdeba3ca8223a56ec9b714034a68498b10d4dd Mon Sep 17 00:00:00 2001 From: "Val Erastov (xibyte)" Date: Sun, 5 Jul 2020 23:17:26 -0700 Subject: [PATCH] edge edge align to double edge edge implementation --- web/app/cad/assembly/dof/EEDOF.ts | 13 ++++++++----- web/app/math/math.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/web/app/cad/assembly/dof/EEDOF.ts b/web/app/cad/assembly/dof/EEDOF.ts index 2a77709d..f2fc170f 100644 --- a/web/app/cad/assembly/dof/EEDOF.ts +++ b/web/app/cad/assembly/dof/EEDOF.ts @@ -4,7 +4,7 @@ import {eqTol} from "../../../brep/geom/tolerance"; import {FaceTouchAlignConstraint} from "../constraints/faceTouchAlign"; import {Plane} from './../../../brep/geom/impl/plane'; import {AssemblyDOF, ModificationResponse} from "./assemblyDOF"; -import {areEqual, clamp, DEG_RAD} from "../../../math/math"; +import {areEqual, clamp, DEG_RAD, lineLineIntersection2d, lineLineIntersection} from "../../../math/math"; import {ConflictDOF} from "./conflictDOF"; import {PPPPDOF} from "./PPPPDOF"; import {EdgeAlignConstraint} from "../constraints/edgeAlign"; @@ -90,13 +90,16 @@ export class EEDOF implements AssemblyDOF { rot.combine(location, location); - - const ptFixed = constr.fixedPart.location.apply(constr.fixedEdge.favorablePoint); const ptMoving = constr.movingPart.location.apply(constr.movingEdge.favorablePoint); + const ptFixed = constr.fixedPart.location.apply(constr.fixedEdge.favorablePoint); - const dir = ptFixed._minus(ptMoving); + const isec1 = lineLineIntersection(this.origin, ptMoving, this.dir, vecA); + const isec2 = lineLineIntersection(this.origin, ptFixed, this.dir, vecB); - // constr.movingPart.location.translateVec(dir); + + const dir = this.dir.multiply(isec2.u1 - isec1.u1); + + constr.movingPart.location.translateVec(dir); return new EEEEDOF(this.origin, this.dir, constr.fixedEdge.favorablePoint, vecB); } diff --git a/web/app/math/math.js b/web/app/math/math.js index cac70a46..d3a7f05f 100644 --- a/web/app/math/math.js +++ b/web/app/math/math.js @@ -300,6 +300,16 @@ export function lineLineIntersection2d(p1, p2, v1, v2) { return [p1[0] + v1[0] * u1, p1[1] + v1[1] * u1]; } +export function lineLineIntersection(p1, p2, v1, v2) { + let zAx = v1.cross(v2); + const n1 = zAx.cross(v1)._normalize(); + const n2 = zAx.cross(v2)._normalize(); + return { + u1: n2.dot(p2.minus(p1)) / n2.dot(v1), + u2: n1.dot(p1.minus(p2)) / n1.dot(v2), + } +} + export const DEG_RAD = Math.PI / 180.0; export const sq = (a) => a * a;