1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAPI_Pln.cpp
4 // Created: 23 Apr 2014
5 // Author: Mikhail PONIKAROV
7 #include <GeomAPI_Pln.h>
8 #include <GeomAPI_Ax3.h>
9 #include <GeomAPI_Pnt.h>
10 #include <GeomAPI_Dir.h>
11 #include <GeomAPI_Lin.h>
12 #include <GeomAPI_XYZ.h>
16 #include <IntAna_QuadQuadGeo.hxx>
18 GeomAPI_Pln::GeomAPI_Pln(const std::shared_ptr<GeomAPI_Ax3>& theAxis)
19 : GeomAPI_Interface(new gp_Ax3(theAxis->impl<gp_Ax3>()))
23 GeomAPI_Pln::GeomAPI_Pln(const std::shared_ptr<GeomAPI_Pnt>& thePoint,
24 const std::shared_ptr<GeomAPI_Dir>& theNormal)
25 : GeomAPI_Interface(new gp_Pln(thePoint->impl<gp_Pnt>(), theNormal->impl<gp_Dir>()))
29 GeomAPI_Pln::GeomAPI_Pln(const double theA, const double theB, const double theC, const double theD)
30 : GeomAPI_Interface(new gp_Pln(theA, theB, theC, theD))
34 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Pln::location() const
36 gp_Pnt aLoc = impl<gp_Pln>().Location();
37 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
40 std::shared_ptr<GeomAPI_Dir> GeomAPI_Pln::direction() const
42 const gp_Dir& aDir = impl<gp_Pln>().Axis().Direction();
43 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
46 std::shared_ptr<GeomAPI_Dir> GeomAPI_Pln::xDirection() const
48 const gp_Dir& aDir = impl<gp_Pln>().XAxis().Direction();
49 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
52 void GeomAPI_Pln::coefficients(double& theA, double& theB, double& theC, double& theD)
54 impl<gp_Pln>().Coefficients(theA, theB, theC, theD);
57 bool GeomAPI_Pln::isCoincident(const std::shared_ptr<GeomAPI_Pln> thePlane,
58 const double theTolerance)
64 const gp_Pln& aMyPln = impl<gp_Pln>();
65 const gp_Pln& anOtherPln = thePlane->impl<gp_Pln>();
66 return (aMyPln.Contains(anOtherPln.Location(), theTolerance) &&
67 aMyPln.Axis().IsParallel(anOtherPln.Axis(), theTolerance));
70 bool GeomAPI_Pln::isParallel(const std::shared_ptr<GeomAPI_Lin> theLine)
72 std::shared_ptr<GeomAPI_XYZ> aLineDir = theLine->direction()->xyz();
73 std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
75 std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
76 std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
78 double aDot = aNormal->dot(aLineDir);
79 return Abs(aDot) < Precision::SquareConfusion();
82 std::shared_ptr<GeomAPI_Pnt>
83 GeomAPI_Pln::intersect(const std::shared_ptr<GeomAPI_Lin>& theLine) const
85 std::shared_ptr<GeomAPI_XYZ> aLineDir = theLine->direction()->xyz();
86 std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
88 std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
89 std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
91 double aDot = aNormal->dot(aLineDir);
92 if (Abs(aDot) < Precision::SquareConfusion())
93 return std::shared_ptr<GeomAPI_Pnt>();
95 double aParam = aNormal->dot(aLocation->decreased(aLineLoc)) / aDot;
96 return std::shared_ptr<GeomAPI_Pnt>(
97 new GeomAPI_Pnt(aLineLoc->added(aLineDir->multiplied(aParam))));
100 std::shared_ptr<GeomAPI_Pnt>
101 GeomAPI_Pln::project(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
103 std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
104 std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
106 std::shared_ptr<GeomAPI_XYZ> aVec = thePoint->xyz()->decreased(aLocation);
107 double aDot = aNormal->dot(aVec);
108 std::shared_ptr<GeomAPI_XYZ> aProjection =
109 aLocation->added(aVec->decreased(aNormal->multiplied(aDot)));
110 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aProjection));
113 double GeomAPI_Pln::distance(const std::shared_ptr<GeomAPI_Pln> thePlane) const
115 const gp_Pln& aMyPln = impl<gp_Pln>();
116 const gp_Pln& anOtherPln = thePlane->impl<gp_Pln>();
118 return aMyPln.Distance(anOtherPln);
121 void GeomAPI_Pln::translate(const std::shared_ptr<GeomAPI_Dir> theDir, double theDist)
123 gp_Vec aVec(theDir->impl<gp_Dir>());
125 aVec.Multiply(theDist);
126 implPtr<gp_Pln>()->Translate(aVec);
129 std::shared_ptr<GeomAPI_Lin>
130 GeomAPI_Pln::intersect(const std::shared_ptr<GeomAPI_Pln> thePlane) const
132 std::shared_ptr<GeomAPI_Lin> aRes;
134 if(!thePlane.get()) {
138 const gp_Pln& aMyPln = impl<gp_Pln>();
139 const gp_Pln& anOtherPln = thePlane->impl<gp_Pln>();
141 IntAna_QuadQuadGeo aQuad(aMyPln, anOtherPln, Precision::Confusion(), Precision::Confusion());
143 if(aQuad.IsDone() != Standard_True) {
147 if(aQuad.NbSolutions() != 1) {
151 gp_Lin aLin = aQuad.Line(1);
152 gp_Pnt aLoc = aLin.Location();
153 gp_Dir aDir = aLin.Direction();
155 std::shared_ptr<GeomAPI_Pnt> aGeomLoc(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
156 std::shared_ptr<GeomAPI_Dir> aGeomDir(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
158 aRes.reset(new GeomAPI_Lin(aGeomLoc, aGeomDir));