From: aml Date: Thu, 5 May 2016 10:55:20 +0000 (+0300) Subject: 0027467: Modeling Algorithms - class Extrema_ExtCC2d does not find extremum between... X-Git-Tag: V7_0_winwerth~60 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=15a954deb57ec441aab4a941464cb75d95983677 0027467: Modeling Algorithms - class Extrema_ExtCC2d does not find extremum between two intersecting lines Line / line analytic treatment is added for 2d case. Test case is added. --- diff --git a/src/Extrema/Extrema_ExtElC2d.cxx b/src/Extrema/Extrema_ExtElC2d.cxx index ae22e42f67..1c237e8c7f 100644 --- a/src/Extrema/Extrema_ExtElC2d.cxx +++ b/src/Extrema/Extrema_ExtElC2d.cxx @@ -36,9 +36,13 @@ 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. @@ -57,15 +61,37 @@ Method: 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; } //============================================================================= diff --git a/tests/bugs/moddata_3/bug27467 b/tests/bugs/moddata_3/bug27467 new file mode 100644 index 0000000000..b6ccf7c908 --- /dev/null +++ b/tests/bugs/moddata_3/bug27467 @@ -0,0 +1,28 @@ +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