修复:在三维坐标系下偏移错误

pull/2177/MERGE
ChenX 1 year ago
parent 0c6accae8b
commit 7774471c19

@ -50,7 +50,7 @@ Vector3 {
exports[`直线偏移 1`] = ` exports[`直线偏移 1`] = `
Vector3 { Vector3 {
"x": -6.123233995736766e-16, "x": 0,
"y": 10, "y": 10,
"z": 0, "z": 0,
} }
@ -58,7 +58,7 @@ Vector3 {
exports[`直线偏移 2`] = ` exports[`直线偏移 2`] = `
Vector3 { Vector3 {
"x": 4.999999999999999, "x": 5,
"y": 10, "y": 10,
"z": 0, "z": 0,
} }

@ -369,7 +369,7 @@ Array [
exports[`圆弧合集 8`] = ` exports[`圆弧合集 8`] = `
Array [ Array [
0, 0,
390.90041837162016, 390.9004183716206,
0, 0,
] ]
`; `;
@ -408,8 +408,8 @@ Array [
exports[`圆弧合集 13`] = ` exports[`圆弧合集 13`] = `
Array [ Array [
-0.8112557813765306, -0.8112557813756212,
-20.020800824495154, -20.0208008244947,
0, 0,
] ]
`; `;
@ -417,7 +417,7 @@ Array [
exports[`圆弧合集 14`] = ` exports[`圆弧合集 14`] = `
Array [ Array [
-890.6332403472697, -890.6332403472697,
901.9543177434239, 901.9543177434243,
0, 0,
] ]
`; `;
@ -425,15 +425,15 @@ Array [
exports[`圆弧合集 15`] = ` exports[`圆弧合集 15`] = `
Array [ Array [
-838.0308338264754, -838.0308338264754,
848.6832679602089, 848.6832679602094,
0, 0,
] ]
`; `;
exports[`圆弧合集 16`] = ` exports[`圆弧合集 16`] = `
Array [ Array [
3.020815205217332, 3.020815205215513,
2.982898780776395, 2.982898780775031,
0, 0,
] ]
`; `;
@ -1601,7 +1601,7 @@ Array [
exports[`测试重叠墙裁剪共面墙 11`] = ` exports[`测试重叠墙裁剪共面墙 11`] = `
Array [ Array [
95.73217955431755, 95.73217955431755,
72.35571710500767, 72.35571710500722,
0, 0,
] ]
`; `;
@ -1744,23 +1744,23 @@ Array [
exports[`直线与圆弧 1`] = ` exports[`直线与圆弧 1`] = `
Array [ Array [
1729.7058390528305, 1729.705839052831,
-484.8814639276738, -484.8814639276739,
0, 0,
] ]
`; `;
exports[`直线与圆弧 2`] = ` exports[`直线与圆弧 2`] = `
Array [ Array [
1228.2620544368035, 1228.262054436803,
-344.3137495380443, -344.3137495380442,
0, 0,
] ]
`; `;
exports[`直线与圆弧 3`] = ` exports[`直线与圆弧 3`] = `
Array [ Array [
-32.39051566134185, -32.39051566134094,
-115.54589778608533, -115.54589778608533,
0, 0,
] ]

@ -280,13 +280,14 @@ export function GetPointAtCurveDir(cu: Curve, pt: Vector3): number
} }
else if (cu instanceof Spline) else if (cu instanceof Spline)
return GetPointAtCurveDir(cu.Convert2Polyline(), pt); return GetPointAtCurveDir(cu.Convert2Polyline(), pt);
//最近点 //最近点
let cp = cu.GetClosestPointTo(pt, false); let cp = cu.GetClosestPointTo(pt, false);
if (equalv3(cp, pt, 1e-6)) return 0; if (equalv3(cp, pt, 1e-6)) return 0;
//最近点参数 //最近点的切线
let cparam = cu.GetParamAtPoint(cp); let deriv = cu.GetFistDeriv(cu.GetParamAtPoint(cp));
let dri = cu.GetFistDeriv(cparam); let vec2 = pt.clone().sub(cp);
let cross = dri.cross(pt.clone().sub(cp)).applyMatrix4(cu.OCSInv); let cross = deriv.cross(vec2).applyMatrix4(cu.OCSInv.setPosition(0, 0, 0));
return -Math.sign(cross.z); return -Math.sign(cross.z);
} }

@ -9,6 +9,7 @@ import { Box3Ext } from '../../Geometry/Box';
import { BufferGeometryUtils } from '../../Geometry/BufferGeometryUtils'; import { BufferGeometryUtils } from '../../Geometry/BufferGeometryUtils';
import { AsVector2, equaln, equalv3, isParallelTo, MoveMatrix, updateGeometry } from '../../Geometry/GeUtils'; import { AsVector2, equaln, equalv3, isParallelTo, MoveMatrix, updateGeometry } from '../../Geometry/GeUtils';
import { PlaneExt } from '../../Geometry/Plane'; import { PlaneExt } from '../../Geometry/Plane';
import { ROTATE_MTX2 } from '../../Geometry/RotateUV';
import { IntersectEllipseAndLine, IntersectLineAndArc, IntersectLineAndCircle, IntersectLineAndLine, IntersectOption, IntersectPolylineAndCurve, IntersectResult, reverseIntersectOption } from '../../GraphicsSystem/IntersectWith'; import { IntersectEllipseAndLine, IntersectLineAndArc, IntersectLineAndCircle, IntersectLineAndLine, IntersectOption, IntersectPolylineAndCurve, IntersectResult, reverseIntersectOption } from '../../GraphicsSystem/IntersectWith';
import { RenderType } from '../../GraphicsSystem/RenderType'; import { RenderType } from '../../GraphicsSystem/RenderType';
import { Factory } from '../CADFactory'; import { Factory } from '../CADFactory';
@ -403,13 +404,12 @@ export class Line extends Curve
GetOffsetCurves(offsetDist: number): Array<Curve> GetOffsetCurves(offsetDist: number): Array<Curve>
{ {
let derv = this.GetFistDeriv(0).normalize().multiplyScalar(offsetDist); let offset = this._EndPoint.clone().sub(this._StartPoint).normalize().multiplyScalar(offsetDist);
derv.applyMatrix4(new Matrix4().makeRotationAxis(this.Normal, -Math.PI / 2)); ROTATE_MTX2.applyVector(offset);
let newLine = this.Clone() as Line; let newLine = this.Clone() as Line;
newLine.SetStartEndPoint( newLine.ClearDraw();
this.StartPoint.add(derv), newLine._StartPoint.add(offset);
this.EndPoint.add(derv) newLine._EndPoint.add(offset);
);
return [newLine]; return [newLine];
} }

Loading…
Cancel
Save