修正判断点在曲线上方向错误的问题

pull/499/head
ChenX 5 years ago
parent a10e525c75
commit b007767e31

@ -0,0 +1,23 @@
import { app } from "../../ApplicationServices/Application";
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
import { Command } from "../../Editor/CommandMachine";
import { PromptStatus } from "../../Editor/PromptResult";
import { Vector3 } from "three";
export class Command_TestPointInCurveDirection implements Command
{
async exec()
{
let cuRes = await app.Editor.GetEntity({ Msg: "选择曲线:", Filter: { filterTypes: [Polyline] } });
if (cuRes.Status !== PromptStatus.OK) return;
let cu = cuRes.Entity;
let box = cu.BoundingBox;
let size = box.getSize(new Vector3());
let maxS = Math.max(...size.toArray());
let box2 = box.expandByScalar(maxS);
}
}

@ -273,6 +273,8 @@ export function GetPointAtCurveDir(cu: Curve, pt: Vector3): boolean
if (cu instanceof Circle)
return !cu.PtInCurve(pt);
//TODO: 当T字形多段线时,最近点将重叠,导致方向结果出错
//最近点
let cp = cu.GetClosestPointTo(pt, false);
//最近点参数
@ -285,13 +287,7 @@ export function GetPointAtCurveDir(cu: Curve, pt: Vector3): boolean
cu instanceof Polyline
&& equaln(floorParam, cparam, 1e-2)
&&
(
cu.IsClose ||
(
floorParam !== 0
&& floorParam !== cu.EndParam
)
)
(cu.IsClose || (floorParam !== 0 && floorParam !== cu.EndParam))
)
{
let plVerCount = cu.NumberOfVertices;
@ -302,22 +298,72 @@ export function GetPointAtCurveDir(cu: Curve, pt: Vector3): boolean
if (floorParam === cu.EndParam) floorParam = 0;
let fIndex = FixIndex(floorParam - 1, plVerCount);
let fpInCir = PointInPolylineArc(cu, fIndex, pt);
if (fpInCir !== 0) return fpInCir < 0;
let npInCir = PointInPolylineArc(cu, floorParam, pt);
if (npInCir !== 0) return npInCir < 0;
let p = cu.GetPointAtParam(floorParam);
let fDer = cu.GetFistDeriv(fIndex + 0.99).normalize();
let nDer = cu.GetFistDeriv(floorParam + 0.01).normalize();
let cu1 = cu.GetCurveAtIndex(fIndex);
let cu2 = cu.GetCurveAtIndex(floorParam);
let cu1Length = cu1.Length;
let cu2Length = cu2.Length;
let minLength = Math.min(cu1Length, cu2Length);
let fDer: Vector3;
let nDer: Vector3;
if (equaln(cu.GetBuilgeAt(fIndex), 0))
fDer = cu.GetFistDeriv(fIndex).normalize();
else
{
let tp = cu1.GetPointAtDistance(cu1Length - minLength * 0.25);
fDer = tp.negate().add(p).normalize();
}
if (equaln(cu.GetBuilgeAt(floorParam), 0))
nDer = cu.GetFistDeriv(floorParam).normalize();
else
{
let tp = cu2.GetPointAtDistance(minLength * 0.25);
nDer = tp.sub(p).normalize();
}
let l1 = new Line(p.clone().sub(fDer), p);
let l2 = new Line(p, p.clone().add(nDer));
let l1 = new Line(p.clone().sub(fDer.clone().multiplyScalar(300)), p);
l1.ColorIndex = 1;
let l2 = new Line(p, p.clone().add(nDer.clone().multiplyScalar(200)));
l2.ColorIndex = 2;
let cp1 = l1.GetClosestPointTo(pt, true);
let cp2 = l2.GetClosestPointTo(pt, true);
if (equalv3(fDer, nDer.clone().negate()))
return true;
// T 型曲线
let nDerN = nDer.clone().negate();
if (equalv3(fDer, nDerN))
{
let frontParam = floorParam;
while (frontParam > 1)
{
let fp = cu.GetPointAtParam(frontParam - 1.2);
fDer.copy(p).sub(fp).normalize();
if (!equalv3(fDer, nDerN))
break;
frontParam--;
}
if (frontParam <= 1)
{
let nextParam = floorParam;
let endParam = cu.EndParam - 1;
while (nextParam < endParam)
{
let np = cu.GetPointAtParam(nextParam + 1.2);
nDer = np.sub(p).normalize();
if (!equalv3(fDer, nDerN))
break;
nextParam++;
}
}
}
if (equalv3(fDer, nDer))
return fDer.cross(pt.clone().sub(cp1)).applyMatrix4(cu.OCSInv).z < 0;

@ -8,8 +8,6 @@ export interface EBox
/**
* x
*
* @export
* @param {EBox[]} arr
*/
export function SortEntityByBox(arr: EBox[], sort: boolean = true)

Loading…
Cancel
Save