X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_Circ2d.cpp;h=5edbab178a47cf77eeac99025a51608f603dc488;hb=857f94a96eb62e69746221f2b919335140b117c6;hp=a5815140920eb6e6f12a01800c0fe6d6518ec8a0;hpb=b9a93c1ac199671649cf2371dfe9fda2bbe65fd0;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_Circ2d.cpp b/src/GeomAPI/GeomAPI_Circ2d.cpp index a58151409..5edbab178 100644 --- a/src/GeomAPI/GeomAPI_Circ2d.cpp +++ b/src/GeomAPI/GeomAPI_Circ2d.cpp @@ -39,7 +39,7 @@ static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, if (aCenter.IsEqual(aPoint, Precision::Confusion())) return NULL; - gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY); + gp_Dir2d aDir(thePointX - theCenterX, thePointY - theCenterY); return newCirc2d(theCenterX, theCenterY, aDir, aRadius); } @@ -55,15 +55,29 @@ static gp_Circ2d* newCirc2d(const std::shared_ptr& theFirstPoint, gp_XY aVec12 = aSecondPnt - aFirstPnt; gp_XY aVec23 = aThirdPnt - aSecondPnt; gp_XY aVec31 = aFirstPnt - aThirdPnt; + + // coefficients to calculate center + double aCoeff1, aCoeff2, aCoeff3; + // square of parallelogram double aSquare2 = aVec12.Crossed(aVec23); aSquare2 *= aSquare2 * 2.0; - if (aSquare2 < 1.e-20) - return NULL; - // coefficients to calculate center - double aCoeff1 = aVec23.Dot(aVec23) / aSquare2 * aVec12.Dot(aVec31.Reversed()); - double aCoeff2 = aVec31.Dot(aVec31) / aSquare2 * aVec23.Dot(aVec12.Reversed()); - double aCoeff3 = aVec12.Dot(aVec12) / aSquare2 * aVec31.Dot(aVec23.Reversed()); + if (aSquare2 < 1.e-20) { + // if two points are equal, build a circle on two different points as on diameter + double aSqLen12 = aVec12.SquareModulus(); + double aSqLen23 = aVec23.SquareModulus(); + double aSqLen31 = aVec31.SquareModulus(); + if (aSqLen12 < Precision::SquareConfusion() && + aSqLen23 < Precision::SquareConfusion() && + aSqLen31 < Precision::SquareConfusion()) + return NULL; + aCoeff1 = aCoeff2 = aCoeff3 = 1.0 / 3.0; + } + else { + aCoeff1 = aVec23.Dot(aVec23) / aSquare2 * aVec12.Dot(aVec31.Reversed()); + aCoeff2 = aVec31.Dot(aVec31) / aSquare2 * aVec23.Dot(aVec12.Reversed()); + aCoeff3 = aVec12.Dot(aVec12) / aSquare2 * aVec31.Dot(aVec23.Reversed()); + } // center gp_XY aCenter = aFirstPnt * aCoeff1 + aSecondPnt * aCoeff2 + aThirdPnt * aCoeff3; // radius @@ -143,7 +157,8 @@ const bool GeomAPI_Circ2d::parameter(const std::shared_ptr thePoi double& theParameter) const { Handle(Geom2d_Circle) aCurve = new Geom2d_Circle(*MY_CIRC2D); - return GeomLib_Tool::Parameter(aCurve, thePoint->impl(), theTolerance, theParameter) == Standard_True; + return GeomLib_Tool::Parameter(aCurve, thePoint->impl(), + theTolerance, theParameter) == Standard_True; } //=================================================================================================