1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <GeomAPI_Pln.h>
22 #include <GeomAPI_Ax3.h>
23 #include <GeomAPI_Pnt.h>
24 #include <GeomAPI_Dir.h>
25 #include <GeomAPI_Lin.h>
26 #include <GeomAPI_XYZ.h>
30 #include <IntAna_QuadQuadGeo.hxx>
32 GeomAPI_Pln::GeomAPI_Pln(const std::shared_ptr<GeomAPI_Ax3>& theAxis)
33 : GeomAPI_Interface(new gp_Ax3(theAxis->impl<gp_Ax3>()))
37 GeomAPI_Pln::GeomAPI_Pln(const std::shared_ptr<GeomAPI_Pnt>& thePoint,
38 const std::shared_ptr<GeomAPI_Dir>& theNormal)
39 : GeomAPI_Interface(new gp_Pln(thePoint->impl<gp_Pnt>(), theNormal->impl<gp_Dir>()))
43 GeomAPI_Pln::GeomAPI_Pln(const double theA, const double theB, const double theC, const double theD)
44 : GeomAPI_Interface(new gp_Pln(theA, theB, theC, theD))
48 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Pln::location() const
50 gp_Pnt aLoc = impl<gp_Pln>().Location();
51 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
54 std::shared_ptr<GeomAPI_Dir> GeomAPI_Pln::direction() const
56 const gp_Dir& aDir = impl<gp_Pln>().Axis().Direction();
57 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
60 std::shared_ptr<GeomAPI_Dir> GeomAPI_Pln::xDirection() const
62 const gp_Dir& aDir = impl<gp_Pln>().XAxis().Direction();
63 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
66 void GeomAPI_Pln::coefficients(double& theA, double& theB, double& theC, double& theD)
68 impl<gp_Pln>().Coefficients(theA, theB, theC, theD);
71 bool GeomAPI_Pln::isCoincident(const std::shared_ptr<GeomAPI_Pln> thePlane,
72 const double theTolerance)
78 const gp_Pln& aMyPln = impl<gp_Pln>();
79 const gp_Pln& anOtherPln = thePlane->impl<gp_Pln>();
80 return (aMyPln.Contains(anOtherPln.Location(), theTolerance) &&
81 aMyPln.Axis().IsParallel(anOtherPln.Axis(), theTolerance));
84 std::shared_ptr<GeomAPI_Pnt>
85 GeomAPI_Pln::intersect(const std::shared_ptr<GeomAPI_Lin>& theLine) const
87 std::shared_ptr<GeomAPI_XYZ> aLineDir = theLine->direction()->xyz();
88 std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
90 std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
91 std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
93 double aDot = aNormal->dot(aLineDir);
94 if (Abs(aDot) < Precision::SquareConfusion())
95 return std::shared_ptr<GeomAPI_Pnt>();
97 double aParam = aNormal->dot(aLocation->decreased(aLineLoc)) / aDot;
98 return std::shared_ptr<GeomAPI_Pnt>(
99 new GeomAPI_Pnt(aLineLoc->added(aLineDir->multiplied(aParam))));
102 std::shared_ptr<GeomAPI_Pnt>
103 GeomAPI_Pln::project(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
105 std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
106 std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
108 std::shared_ptr<GeomAPI_XYZ> aVec = thePoint->xyz()->decreased(aLocation);
109 double aDot = aNormal->dot(aVec);
110 std::shared_ptr<GeomAPI_XYZ> aProjection =
111 aLocation->added(aVec->decreased(aNormal->multiplied(aDot)));
112 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aProjection));
115 double GeomAPI_Pln::distance(const std::shared_ptr<GeomAPI_Pln> thePlane) const
117 const gp_Pln& aMyPln = impl<gp_Pln>();
118 const gp_Pln& anOtherPln = thePlane->impl<gp_Pln>();
120 return aMyPln.Distance(anOtherPln);
123 void GeomAPI_Pln::translate(const std::shared_ptr<GeomAPI_Dir> theDir, double theDist)
125 gp_Vec aVec(theDir->impl<gp_Dir>());
127 aVec.Multiply(theDist);
128 implPtr<gp_Pln>()->Translate(aVec);
131 std::shared_ptr<GeomAPI_Lin>
132 GeomAPI_Pln::intersect(const std::shared_ptr<GeomAPI_Pln> thePlane) const
134 std::shared_ptr<GeomAPI_Lin> aRes;
136 if(!thePlane.get()) {
140 const gp_Pln& aMyPln = impl<gp_Pln>();
141 const gp_Pln& anOtherPln = thePlane->impl<gp_Pln>();
143 IntAna_QuadQuadGeo aQuad(aMyPln, anOtherPln, Precision::Confusion(), Precision::Confusion());
145 if(aQuad.IsDone() != Standard_True) {
149 if(aQuad.NbSolutions() != 1) {
153 gp_Lin aLin = aQuad.Line(1);
154 gp_Pnt aLoc = aLin.Location();
155 gp_Dir aDir = aLin.Direction();
157 std::shared_ptr<GeomAPI_Pnt> aGeomLoc(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
158 std::shared_ptr<GeomAPI_Dir> aGeomDir(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
160 aRes.reset(new GeomAPI_Lin(aGeomLoc, aGeomDir));