修改平行直线交点位置

pull/68/head
Zoe 6 years ago
parent dde2c6081c
commit 0abcce2911

@ -140,9 +140,9 @@ Vector3 {
exports[`三维空间直线相交测试 2`] = `
Vector3 {
"x": 4.75,
"y": 4.75,
"z": 4.75,
"x": 1.5,
"y": 1.5,
"z": 1.5,
}
`;
@ -164,7 +164,7 @@ Vector3 {
exports[`相交测试 2`] = `
Vector3 {
"x": 2.5,
"x": 3,
"y": 0,
"z": 0,
}

@ -237,16 +237,38 @@ export function IntersectLAndLFor3D(p1: Vector3, p2: Vector3, p3: Vector3, p4: V
let v1 = p2.clone().sub(p1).normalize();
let v2 = p4.clone().sub(p3).normalize();
let w = p3.clone().sub(p1);
if (Math.abs(v1.dot(v2)) === 1)
let w = p3.clone().sub(p1).normalize();
if (equaln(Math.abs(v1.dot(v2)), 1) && equaln(Math.abs(v1.dot(w)), 1)) //平行共线
{
let tmpLine = new Line(p1, p2);
let par = tmpLine.GetParamAtPoint(p3);
if (par)
const selectPt = (line: Line, p1: Vector3, p2: Vector3) =>
{
//FIXME:这样拿交点会导致判断点在线上发生错误
pt = midPoint(midPoint(p1, p2), midPoint(p3, p4));
let tmpP: Vector3;
if (line.PtOnCurve(p1))
{
tmpP = p1;
} else if (line.PtOnCurve(p2))
tmpP = p2;
else
{
let dist1 = line.EndPoint.distanceToSquared(p1);
let dist2 = line.EndPoint.distanceToSquared(p2);
tmpP = dist1 > dist2 ? p1 : p2;
}
return tmpP;
}
let tmpLine = new Line(p1, p2);
let tmpLine2 = new Line(p3, p4);
let tmpP1 = selectPt(tmpLine, p3, p4);
let tmpP2: Vector3 = selectPt(tmpLine2, p1, p2);
pt = midPoint(tmpP1, tmpP2);
} else if (Math.abs(v1.dot(v2)) === 1) //平行不共线
{
return undefined;
}
else if (equaln(getDeterminantFor3V(v1, v2, w), 0, 0.01))
{

@ -1055,12 +1055,13 @@ export class PolyOffestUtil3
{
private m_Polyline: Polyline;
private m_OffestDist: number;
offDir: number;
private m_OffDir: number;
private IsKeepAllCurves = false;
constructor(pl: Polyline, offest: number)
{
this.m_Polyline = pl;
this.m_OffestDist = offest;
this.offDir = Math.sign(this.m_OffestDist) * Math.sign(this.m_Polyline.Area2);
this.m_OffDir = Math.sign(this.m_OffestDist) * Math.sign(this.m_Polyline.Area2);
}
//偏移
GetOffsetCurves(): Curve[]
@ -1083,12 +1084,18 @@ export class PolyOffestUtil3
let cus = this.trimByContours(newPls, contours);
// return cus;
if (this.m_Polyline.IsClose && this.offDir < 0)
if (this.m_Polyline.IsClose && this.m_OffDir < 0)
{
cus = cus.filter(pl => isTargetCurInSourceCur(this.m_Polyline, pl))
}
return this.linkSelfingCurves(cus);
if (this.IsKeepAllCurves)
{
return this.linkSelfingCurves(cus);
} else
{
return this.linkSelfingCurves(cus);
}
}
//偏移曲线
@ -1286,6 +1293,7 @@ export class PolyOffestUtil3
buildArcJoinList(cir2, laterLine.StartPoint);
}
}
// 补完圆弧直接退出函数
return;
}
}
@ -1427,9 +1435,9 @@ export class PolyOffestUtil3
if (equaln(parForFront, 0))
{
//理论应该把该段移除出来
}
else if (equaln(parForFront, 1))
else if (equaln(parForFront, 1, 1e-6))
{
pl.Join(frontLine);
}
@ -1440,7 +1448,7 @@ export class PolyOffestUtil3
cus.unshift(spliteCusForFront[1]);
j++;
}
if (equaln(parForLater, 0))
if (equaln(parForLater, 0, 1e-6))
frontLine = cus.splice(j, 1)[0];
else
{

Loading…
Cancel
Save