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, const gp_Dir& theDir, const double theRadius)
21 return new gp_Circ(gp_Ax2(theCenter, theDir), theRadius);
24 GeomAPI_Circ::GeomAPI_Circ(const boost::shared_ptr<GeomAPI_Pnt>& theCenter,
25 const boost::shared_ptr<GeomAPI_Dir>& theDir, double theRadius)
26 : GeomAPI_Interface(newCirc(theCenter->impl<gp_Pnt>(), theDir->impl<gp_Dir>(), theRadius))
30 const boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::project(
31 const boost::shared_ptr<GeomAPI_Pnt>& thePoint) const
33 boost::shared_ptr<GeomAPI_Pnt> aResult;
37 Handle(Geom_Circle) aCircle = new Geom_Circle(*MY_CIRC);
39 const gp_Pnt& aPoint = thePoint->impl<gp_Pnt>();
41 GeomAPI_ProjectPointOnCurve aProj(aPoint, aCircle);
42 Standard_Integer aNbPoint = aProj.NbPoints();
44 double aMinDistance = 0, aDistance;
45 for (Standard_Integer j = 1; j <= aNbPoint; j++) {
46 gp_Pnt aNewPoint = aProj.Point(j);
47 aDistance = aNewPoint.Distance(aPoint);
48 if (!aMinDistance || aDistance < aMinDistance) {
49 aMinDistance = aDistance;
50 aResult = boost::shared_ptr<GeomAPI_Pnt>(
51 new GeomAPI_Pnt(aNewPoint.X(), aNewPoint.Y(), aNewPoint.Z()));
58 const boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::center() const
60 const gp_Pnt& aCenter = MY_CIRC->Location();
61 return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z()));
64 double GeomAPI_Circ::radius() const
66 return MY_CIRC->Radius();