1 // File: GeomAPI_Circ2cpp
2 // Created: 24 Jun 2014
3 // Author: Artem ZHIDKOV
5 #include <GeomAPI_Circ.h>
6 #include <GeomAPI_Pnt.h>
7 #include <GeomAPI_Dir.h>
10 #include <gp_Circ.hxx>
14 #include <Geom_Circle.hxx>
15 #include <GeomAPI_ProjectPointOnCurve.hxx>
17 #define MY_CIRC static_cast<gp_Circ*>(myImpl)
19 static gp_Circ* newCirc(const gp_Pnt& theCenter,
21 const double theRadius)
23 return new gp_Circ(gp_Ax2(theCenter, theDir), theRadius);
26 GeomAPI_Circ::GeomAPI_Circ(const boost::shared_ptr<GeomAPI_Pnt>& theCenter,
27 const boost::shared_ptr<GeomAPI_Dir>& theDir,
29 : GeomAPI_Interface(newCirc(theCenter->impl<gp_Pnt>(),
30 theDir->impl<gp_Dir>(), theRadius))
34 const boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::project(const boost::shared_ptr<GeomAPI_Pnt>& thePoint) const
36 boost::shared_ptr<GeomAPI_Pnt> aResult;
40 Handle(Geom_Circle) aCircle = new Geom_Circle(*MY_CIRC);
42 const gp_Pnt& aPoint = thePoint->impl<gp_Pnt>();
44 GeomAPI_ProjectPointOnCurve aProj(aPoint, aCircle);
45 Standard_Integer aNbPoint = aProj.NbPoints();
48 double aMinDistance = 0, aDistance;
49 for (Standard_Integer j = 1; j <= aNbPoint; j++)
51 gp_Pnt aNewPoint = aProj.Point(j);
52 aDistance = aNewPoint.Distance(aPoint);
53 if (!aMinDistance || aDistance < aMinDistance)
55 aMinDistance = aDistance;
56 aResult = boost::shared_ptr<GeomAPI_Pnt>(
57 new GeomAPI_Pnt(aNewPoint.X(), aNewPoint.Y(), aNewPoint.Z()));
64 const boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::center() const
66 const gp_Pnt& aCenter = MY_CIRC->Location();
67 return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z()));
70 double GeomAPI_Circ::radius() const
72 return MY_CIRC->Radius();