1 // Copyright (C) 2018-20xx 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <GeomAPI_Angle.h>
23 #include <GeomAPI_Edge.h>
24 #include <GeomAPI_Pnt.h>
26 #include <BRep_Tool.hxx>
28 #include <Geom_Curve.hxx>
29 #include <GeomAPI_ProjectPointOnCurve.hxx>
30 #include <Precision.hxx>
31 #include <TopoDS_Edge.hxx>
33 /// \struct AngleDirections
34 /// \brief Used to store info about angle.
35 struct AngleDirections {
40 #define MY_ANGLE implPtr<AngleDirections>()
41 #define PI 3.1415926535897932
44 GeomAPI_Angle::GeomAPI_Angle(const std::shared_ptr<GeomAPI_Edge>& theEdge1,
45 const std::shared_ptr<GeomAPI_Edge>& theEdge2,
46 const std::shared_ptr<GeomAPI_Pnt>& thePoint)
48 gp_Pnt aPoint = thePoint->impl<gp_Pnt>();
49 const TopoDS_Edge& anEdge1 = theEdge1->impl<TopoDS_Edge>();
50 const TopoDS_Edge& anEdge2 = theEdge2->impl<TopoDS_Edge>();
53 Handle(Geom_Curve) aCurve1 = BRep_Tool::Curve(anEdge1, aF1, aL1);
55 Handle(Geom_Curve) aCurve2 = BRep_Tool::Curve(anEdge2, aF2, aL2);
57 AngleDirections* anAngle = new AngleDirections;
60 GeomAPI_ProjectPointOnCurve aProj1(aPoint, aCurve1);
61 if (aProj1.NbPoints() > 0) {
62 aCurve1->D1(aProj1.LowerDistanceParameter(), aP, anAngle->myDir1);
63 if (aCurve1->Value(aF1).SquareDistance(aPoint) < aCurve1->Value(aL1).SquareDistance(aPoint))
64 anAngle->myDir1.Reverse();
67 GeomAPI_ProjectPointOnCurve aProj2(aPoint, aCurve2);
68 if (aProj2.NbPoints() > 0) {
69 aCurve2->D1(aProj2.LowerDistanceParameter(), aP, anAngle->myDir2);
70 if (aCurve2->Value(aF2).SquareDistance(aPoint) < aCurve2->Value(aL2).SquareDistance(aPoint))
71 anAngle->myDir2.Reverse();
77 GeomAPI_Angle::GeomAPI_Angle(const std::shared_ptr<GeomAPI_Pnt>& thePoint1,
78 const std::shared_ptr<GeomAPI_Pnt>& thePoint2,
79 const std::shared_ptr<GeomAPI_Pnt>& thePoint3)
81 gp_Pnt aPoint1 = thePoint1->impl<gp_Pnt>();
82 gp_Pnt aPoint2 = thePoint2->impl<gp_Pnt>();
83 gp_Pnt aPoint3 = thePoint3->impl<gp_Pnt>();
85 AngleDirections* anAngle = new AngleDirections;
86 anAngle->myDir1.SetXYZ(aPoint1.XYZ() - aPoint2.XYZ());
87 anAngle->myDir2.SetXYZ(aPoint3.XYZ() - aPoint2.XYZ());
91 double GeomAPI_Angle::angleDegree()
93 return angleRadian() * 180.0 / PI;
96 double GeomAPI_Angle::angleRadian()
98 AngleDirections* anAngle = MY_ANGLE;
99 if (anAngle->myDir1.SquareMagnitude() < Precision::SquareConfusion() ||
100 anAngle->myDir2.SquareMagnitude() < Precision::SquareConfusion())
103 gp_Dir aDir1(anAngle->myDir1);
104 gp_Dir aDir2(anAngle->myDir2);
105 double aRes = aDir1.Angle(aDir2);
106 aRes = ElCLib::InPeriod(aRes, 0.0, 2.0 * PI);
107 if (Abs(aRes) < 1.e-12)