1 // Copyright (C) 2018-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <GeomAPI_Angle.h>
22 #include <GeomAPI_Edge.h>
23 #include <GeomAPI_Pnt.h>
25 #include <BRep_Tool.hxx>
27 #include <Geom_Curve.hxx>
28 #include <GeomAPI_ProjectPointOnCurve.hxx>
29 #include <Precision.hxx>
30 #include <TopoDS_Edge.hxx>
32 /// \struct AngleDirections
33 /// \brief Used to store info about angle.
34 struct AngleDirections {
39 #define MY_ANGLE implPtr<AngleDirections>()
40 #define PI 3.1415926535897932
43 GeomAPI_Angle::GeomAPI_Angle(const std::shared_ptr<GeomAPI_Edge>& theEdge1,
44 const std::shared_ptr<GeomAPI_Edge>& theEdge2,
45 const std::shared_ptr<GeomAPI_Pnt>& thePoint)
47 gp_Pnt aPoint = thePoint->impl<gp_Pnt>();
48 const TopoDS_Edge& anEdge1 = theEdge1->impl<TopoDS_Edge>();
49 const TopoDS_Edge& anEdge2 = theEdge2->impl<TopoDS_Edge>();
52 Handle(Geom_Curve) aCurve1 = BRep_Tool::Curve(anEdge1, aF1, aL1);
54 Handle(Geom_Curve) aCurve2 = BRep_Tool::Curve(anEdge2, aF2, aL2);
56 AngleDirections* anAngle = new AngleDirections;
59 GeomAPI_ProjectPointOnCurve aProj1(aPoint, aCurve1);
60 if (aProj1.NbPoints() > 0) {
61 aCurve1->D1(aProj1.LowerDistanceParameter(), aP, anAngle->myDir1);
62 if (aCurve1->Value(aF1).SquareDistance(aPoint) < aCurve1->Value(aL1).SquareDistance(aPoint))
63 anAngle->myDir1.Reverse();
66 GeomAPI_ProjectPointOnCurve aProj2(aPoint, aCurve2);
67 if (aProj2.NbPoints() > 0) {
68 aCurve2->D1(aProj2.LowerDistanceParameter(), aP, anAngle->myDir2);
69 if (aCurve2->Value(aF2).SquareDistance(aPoint) < aCurve2->Value(aL2).SquareDistance(aPoint))
70 anAngle->myDir2.Reverse();
76 GeomAPI_Angle::GeomAPI_Angle(const std::shared_ptr<GeomAPI_Pnt>& thePoint1,
77 const std::shared_ptr<GeomAPI_Pnt>& thePoint2,
78 const std::shared_ptr<GeomAPI_Pnt>& thePoint3)
80 gp_Pnt aPoint1 = thePoint1->impl<gp_Pnt>();
81 gp_Pnt aPoint2 = thePoint2->impl<gp_Pnt>();
82 gp_Pnt aPoint3 = thePoint3->impl<gp_Pnt>();
84 AngleDirections* anAngle = new AngleDirections;
85 anAngle->myDir1.SetXYZ(aPoint1.XYZ() - aPoint2.XYZ());
86 anAngle->myDir2.SetXYZ(aPoint3.XYZ() - aPoint2.XYZ());
90 double GeomAPI_Angle::angleDegree()
92 return angleRadian() * 180.0 / PI;
95 double GeomAPI_Angle::angleRadian()
97 AngleDirections* anAngle = MY_ANGLE;
98 if (anAngle->myDir1.SquareMagnitude() < Precision::SquareConfusion() ||
99 anAngle->myDir2.SquareMagnitude() < Precision::SquareConfusion())
102 gp_Dir aDir1(anAngle->myDir1);
103 gp_Dir aDir2(anAngle->myDir2);
104 double aRes = aDir1.Angle(aDir2);
105 aRes = ElCLib::InPeriod(aRes, 0.0, 2.0 * PI);
106 if (Abs(aRes) < 1.e-12)