Extrema_ExtElC2d::Extrema_ExtElC2d () { myDone = Standard_False; }
//=============================================================================
-Extrema_ExtElC2d::Extrema_ExtElC2d (const gp_Lin2d& C1,
- const gp_Lin2d& C2,
- const Standard_Real)
+//=======================================================================
+//function : Extrema_ExtElC2d
+//purpose :
+//=======================================================================
+Extrema_ExtElC2d::Extrema_ExtElC2d (const gp_Lin2d& C1,
+ const gp_Lin2d& C2,
+ const Standard_Real)
/*-----------------------------------------------------------------------------
Function:
Find min distance between 2 straight lines.
myIsPar = Standard_False;
myNbExt = 0;
- gp_Dir2d D1 = C1.Direction();
- gp_Dir2d D2 = C2.Direction();
- if (D1.IsParallel(D2, Precision::Angular())) {
+ gp_Vec2d D1(C1.Direction());
+ gp_Vec2d D2(C2.Direction());
+ if (D1.IsParallel(D2, Precision::Angular()))
+ {
myIsPar = Standard_True;
mySqDist[0] = C2.SquareDistance(C1.Location());
}
- else {
- myNbExt = 0;
+ else
+ {
+ // Vector from P1 to P2 (P2 - P1).
+ gp_Vec2d aP1P2(C1.Location(), C2.Location());
+
+ // Solve linear system using Cramer's rule:
+ // D1.X * t1 + D2.X * (-t2) = P2.X - P1.X
+ // D1.Y * t1 + D2.Y * (-t2) = P2.Y - P1.Y
+
+ // There is no division by zero since lines are not parallel.
+ Standard_Real aDelim = 1 / (D1^D2);
+
+ Standard_Real aParam1 = (aP1P2 ^ D2) * aDelim;
+ Standard_Real aParam2 = -(D1 ^ aP1P2) * aDelim; // -1.0 coefficient before t2.
+
+ gp_Pnt2d P1 = ElCLib::Value(aParam1, C1);
+ gp_Pnt2d P2 = ElCLib::Value(aParam2, C2);
+
+ mySqDist[myNbExt] = 0.0;
+ myPoint[myNbExt][0] = Extrema_POnCurv2d(aParam1,P1);
+ myPoint[myNbExt][1] = Extrema_POnCurv2d(aParam2,P2);
+ myNbExt = 1;
}
+
myDone = Standard_True;
}
//=============================================================================
--- /dev/null
+puts "============"
+puts "OCC27467"
+puts "============"
+puts ""
+#########################################################################
+# Modeling Algorithms - class Extrema_ExtCC2d does not find extremum between two intersecting lines
+# Analytical solver can not work on 2 lines.
+#########################################################################
+
+line l1 0 0 0 -1
+trim l1 l1 0 23
+
+line l2 1 -9.5 -1 -0
+trim l2 l2 0 2
+set info [2dextrema l1 l2]
+
+# Number of solutions check.
+# There should be only one solution - intersection point.
+if {[llength $info] != 4} {
+ ERROR: Incorrect number of solutions.
+}
+
+# Check distance.
+regexp "dist 1: +(\[-0-9.+eE\]+)" $info full aDist
+set absTol 1.0e-9
+set relTol 0.001
+set aDist_Exp 0.0
+checkreal "Distance value check" $aDist $aDist_Exp $absTol $relTol