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>
8 #include <GeomAPI_Pnt.h>
9 #include <GeomAPI_Dir.h>
12 #include <gp_Circ.hxx>
16 #include <Geom_Circle.hxx>
17 #include <GeomAPI_ProjectPointOnCurve.hxx>
19 #define MY_CIRC implPtr<gp_Circ>()
21 static gp_Circ* newCirc(const gp_Pnt& theCenter, const gp_Dir& theDir, const double theRadius)
23 return new gp_Circ(gp_Ax2(theCenter, theDir), theRadius);
26 GeomAPI_Circ::GeomAPI_Circ(const std::shared_ptr<GeomAPI_Pnt>& theCenter,
27 const std::shared_ptr<GeomAPI_Dir>& theDir, double theRadius)
28 : GeomAPI_Interface(newCirc(theCenter->impl<gp_Pnt>(), theDir->impl<gp_Dir>(), theRadius))
32 const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::project(
33 const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
35 std::shared_ptr<GeomAPI_Pnt> aResult;
39 Handle(Geom_Circle) aCircle = new Geom_Circle(*MY_CIRC);
41 const gp_Pnt& aPoint = thePoint->impl<gp_Pnt>();
43 GeomAPI_ProjectPointOnCurve aProj(aPoint, aCircle);
44 Standard_Integer aNbPoint = aProj.NbPoints();
46 double aMinDistance = 0, aDistance;
47 for (Standard_Integer j = 1; j <= aNbPoint; j++) {
48 gp_Pnt aNewPoint = aProj.Point(j);
49 aDistance = aNewPoint.Distance(aPoint);
50 if (!aMinDistance || aDistance < aMinDistance) {
51 aMinDistance = aDistance;
52 aResult = std::shared_ptr<GeomAPI_Pnt>(
53 new GeomAPI_Pnt(aNewPoint.X(), aNewPoint.Y(), aNewPoint.Z()));
60 const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::center() const
62 const gp_Pnt& aCenter = MY_CIRC->Location();
63 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z()));
66 double GeomAPI_Circ::radius() const
68 return MY_CIRC->Radius();