1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAPI_Circ2cpp
4 // Created: 24 Jun 2014
5 // Author: Artem ZHIDKOV
7 #include <GeomAPI_Circ.h>
9 #include <GeomAPI_Ax2.h>
10 #include <GeomAPI_Pnt.h>
11 #include <GeomAPI_Dir.h>
14 #include <gp_Circ.hxx>
18 #include <Geom_Circle.hxx>
19 #include <GeomAPI_ProjectPointOnCurve.hxx>
20 #include <GeomLib_Tool.hxx>
22 #define MY_CIRC implPtr<gp_Circ>()
24 static gp_Circ* newCirc(const gp_Pnt& theCenter, const gp_Dir& theDir, const double theRadius)
26 return new gp_Circ(gp_Ax2(theCenter, theDir), theRadius);
29 //=================================================================================================
30 GeomAPI_Circ::GeomAPI_Circ(const std::shared_ptr<GeomAPI_Ax2> theAx2,
31 const double theRadius)
32 : GeomAPI_Interface(new gp_Circ(theAx2->impl<gp_Ax2>(), theRadius))
38 //=================================================================================================
39 GeomAPI_Circ::GeomAPI_Circ(const std::shared_ptr<GeomAPI_Pnt>& theCenter,
40 const std::shared_ptr<GeomAPI_Dir>& theDir, double theRadius)
41 : GeomAPI_Interface(newCirc(theCenter->impl<gp_Pnt>(), theDir->impl<gp_Dir>(), theRadius))
45 //=================================================================================================
46 const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::center() const
48 const gp_Pnt& aCenter = MY_CIRC->Location();
49 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z()));
52 //=================================================================================================
53 double GeomAPI_Circ::radius() const
55 return MY_CIRC->Radius();
58 //=================================================================================================
59 const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::project(
60 const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
62 std::shared_ptr<GeomAPI_Pnt> aResult;
66 Handle(Geom_Circle) aCircle = new Geom_Circle(*MY_CIRC);
68 const gp_Pnt& aPoint = thePoint->impl<gp_Pnt>();
70 GeomAPI_ProjectPointOnCurve aProj(aPoint, aCircle);
71 Standard_Integer aNbPoint = aProj.NbPoints();
73 double aMinDistance = 0, aDistance;
74 for (Standard_Integer j = 1; j <= aNbPoint; j++) {
75 gp_Pnt aNewPoint = aProj.Point(j);
76 aDistance = aNewPoint.Distance(aPoint);
77 if (!aMinDistance || aDistance < aMinDistance) {
78 aMinDistance = aDistance;
79 aResult = std::shared_ptr<GeomAPI_Pnt>(
80 new GeomAPI_Pnt(aNewPoint.X(), aNewPoint.Y(), aNewPoint.Z()));
87 //=================================================================================================
88 const bool GeomAPI_Circ::parameter(const std::shared_ptr<GeomAPI_Pnt> thePoint,
89 const double theTolerance,
90 double& theParameter) const
92 Handle(Geom_Circle) aCurve = new Geom_Circle(*MY_CIRC);
93 return GeomLib_Tool::Parameter(aCurve, thePoint->impl<gp_Pnt>(), theTolerance, theParameter) == Standard_True;
96 //=================================================================================================
97 std::shared_ptr<GeomAPI_Dir> GeomAPI_Circ::normal() const
99 const gp_Ax1& anAxis = MY_CIRC->Axis();
100 const gp_Dir& aDir = anAxis.Direction();
101 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));