]> OCCT Git - occt.git/commitdiff
0033418: Modeling Algorithms - BRepExtrema_DistShapeShape wrong arc ellipse - point... CR33418_1
authorakaftasev <akaftasev@opencascade.com>
Wed, 2 Aug 2023 09:35:30 +0000 (10:35 +0100)
committerakaftasev <akaftasev@opencascade.com>
Thu, 3 Aug 2023 15:55:35 +0000 (16:55 +0100)
Wrong calculation of distance arises for ellipse with MajorRadius == MinorRadius when first or last parameter of trimmed ellipse more then 2*pi
This case should be calculated as circle

src/Extrema/Extrema_ExtPElC.cxx
tests/bugs/modalg_8/bug33418 [new file with mode: 0644]

index 53514f594ba4df720bedfcc515985de612cf332a..0142b678b9e018dcf9bd229e1e4806f772d6d79e 100644 (file)
@@ -217,6 +217,10 @@ Method:
      Then, (1) <=> (A*Cos-X,B*Sin-Y).(-A*Sin,B*Cos) = 0.
                     (B**2-A**2)*Cos*Sin - B*Y*Cos + A*X*Sin = 0.
      Use algorithm math_TrigonometricFunctionRoots to solve this equation.
+
+  Addition:
+    In case, when MajorRadius == MinorRadius calcualtion errors may occur
+    This case should be processed as Circle
 -----------------------------------------------------------------------------*/
 {
   myDone = Standard_False;
@@ -229,6 +233,53 @@ Method:
   gp_Vec Trsl = Axe.Multiplied(-(gp_Vec(O,P).Dot(Axe)));
   gp_Pnt Pp = P.Translated(Trsl);
 
+  if (Abs(C.MajorRadius() - C.MinorRadius() < Precision::Confusion()))
+  {
+    gp_Vec OPp(O, Pp);
+    if (OPp.Magnitude() < Tol) { return; }
+    Standard_Real Usol[2];
+    Usol[0] = C.XAxis().Direction().AngleWithRef(OPp, Axe); // -M_PI<U1<M_PI
+
+    const Standard_Real aAngTol = Precision::Angular();
+    if (Usol[0] + M_PI < aAngTol)
+      Usol[0] = -M_PI;
+    else if (Usol[0] - M_PI > -aAngTol)
+      Usol[0] = M_PI;
+
+    Usol[1] = Usol[0] + M_PI;
+
+    Standard_Real myuinf = Uinf;
+    Standard_Real TolU, aR;
+    aR = C.MajorRadius();
+    TolU = Precision::Infinite();
+    if (aR > gp::Resolution()) {
+      TolU = Tol / aR;
+    }
+    //
+    ElCLib::AdjustPeriodic(Uinf, Uinf + 2 * M_PI, TolU, myuinf, Usol[0]);
+    ElCLib::AdjustPeriodic(Uinf, Uinf + 2 * M_PI, TolU, myuinf, Usol[1]);
+    if (((Usol[0] - 2 * M_PI - Uinf) < TolU) && ((Usol[0] - 2 * M_PI - Uinf) > -TolU)) Usol[0] = Uinf;
+    if (((Usol[1] - 2 * M_PI - Uinf) < TolU) && ((Usol[1] - 2 * M_PI - Uinf) > -TolU)) Usol[1] = Uinf;
+
+
+    // 3- Calculate extrema in [Umin,Umax] ...
+
+    gp_Pnt Cu;
+    Standard_Real Us;
+    for (Standard_Integer NoSol = 0; NoSol <= 1; NoSol++) {
+      Us = Usol[NoSol];
+      if (((Uinf - Us) < TolU) && ((Us - Usup) < TolU)) {
+        Cu = ElCLib::Value(Us, C);
+        mySqDist[myNbExt] = Cu.SquareDistance(P);
+        myIsMin[myNbExt] = (NoSol == 0);
+        myPoint[myNbExt] = Extrema_POnCurv(Us, Cu);
+        myNbExt++;
+      }
+    }
+    myDone = Standard_True;
+    return;
+  }
+
 // 2- Calculation of solutions ...
 
   Standard_Integer NoSol, NbSol;
diff --git a/tests/bugs/modalg_8/bug33418 b/tests/bugs/modalg_8/bug33418
new file mode 100644 (file)
index 0000000..d0ca280
--- /dev/null
@@ -0,0 +1,13 @@
+puts "================================================================="
+puts "0033418: Modeling Algorithms - BRepExtrema_DistShapeShape wrong arc ellipse - point result"
+puts "================================================================="
+puts ""
+
+ellipse el 0 0 0 0 1 0 1 1
+trim el el 4.71238898038 1.57079632679
+mkedge el el
+vertex v 0 0 1.5
+distmini d el v
+if {[dval d_val] > 0.5000001} {
+  puts "ERROR: Wrong distance calculation"
+}