1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include <GeomAPI_Pln.h>
21 #include <GeomAPI_Ax3.h>
22 #include <GeomAPI_Pnt.h>
23 #include <GeomAPI_Dir.h>
24 #include <GeomAPI_Lin.h>
25 #include <GeomAPI_XYZ.h>
29 #include <IntAna_QuadQuadGeo.hxx>
31 GeomAPI_Pln::GeomAPI_Pln(const std::shared_ptr<GeomAPI_Ax3>& theAxis)
32 : GeomAPI_Interface(new gp_Ax3(theAxis->impl<gp_Ax3>()))
36 GeomAPI_Pln::GeomAPI_Pln(const std::shared_ptr<GeomAPI_Pnt>& thePoint,
37 const std::shared_ptr<GeomAPI_Dir>& theNormal)
38 : GeomAPI_Interface(new gp_Pln(thePoint->impl<gp_Pnt>(), theNormal->impl<gp_Dir>()))
42 GeomAPI_Pln::GeomAPI_Pln(const double theA, const double theB, const double theC, const double theD)
43 : GeomAPI_Interface(new gp_Pln(theA, theB, theC, theD))
47 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Pln::location() const
49 gp_Pnt aLoc = impl<gp_Pln>().Location();
50 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
53 std::shared_ptr<GeomAPI_Dir> GeomAPI_Pln::direction() const
55 const gp_Dir& aDir = impl<gp_Pln>().Axis().Direction();
56 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
59 std::shared_ptr<GeomAPI_Dir> GeomAPI_Pln::xDirection() const
61 const gp_Dir& aDir = impl<gp_Pln>().XAxis().Direction();
62 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
65 void GeomAPI_Pln::coefficients(double& theA, double& theB, double& theC, double& theD)
67 impl<gp_Pln>().Coefficients(theA, theB, theC, theD);
70 bool GeomAPI_Pln::isCoincident(const std::shared_ptr<GeomAPI_Pln> thePlane,
71 const double theTolerance)
77 const gp_Pln& aMyPln = impl<gp_Pln>();
78 const gp_Pln& anOtherPln = thePlane->impl<gp_Pln>();
79 return (aMyPln.Contains(anOtherPln.Location(), theTolerance) &&
80 aMyPln.Axis().IsParallel(anOtherPln.Axis(), theTolerance));
83 std::shared_ptr<GeomAPI_Pnt>
84 GeomAPI_Pln::intersect(const std::shared_ptr<GeomAPI_Lin>& theLine) const
86 std::shared_ptr<GeomAPI_XYZ> aLineDir = theLine->direction()->xyz();
87 std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
89 std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
90 std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
92 double aDot = aNormal->dot(aLineDir);
93 if (Abs(aDot) < Precision::SquareConfusion())
94 return std::shared_ptr<GeomAPI_Pnt>();
96 double aParam = aNormal->dot(aLocation->decreased(aLineLoc)) / aDot;
97 return std::shared_ptr<GeomAPI_Pnt>(
98 new GeomAPI_Pnt(aLineLoc->added(aLineDir->multiplied(aParam))));
101 std::shared_ptr<GeomAPI_Pnt>
102 GeomAPI_Pln::project(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
104 std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
105 std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
107 std::shared_ptr<GeomAPI_XYZ> aVec = thePoint->xyz()->decreased(aLocation);
108 double aDot = aNormal->dot(aVec);
109 std::shared_ptr<GeomAPI_XYZ> aProjection =
110 aLocation->added(aVec->decreased(aNormal->multiplied(aDot)));
111 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aProjection));
114 double GeomAPI_Pln::distance(const std::shared_ptr<GeomAPI_Pln> thePlane) const
116 const gp_Pln& aMyPln = impl<gp_Pln>();
117 const gp_Pln& anOtherPln = thePlane->impl<gp_Pln>();
119 return aMyPln.Distance(anOtherPln);
122 double GeomAPI_Pln::distance(const std::shared_ptr<GeomAPI_Pnt> thePoint) const
124 const gp_Pln& aMyPln = impl<gp_Pln>();
125 const gp_Pnt& aPnt = thePoint->impl<gp_Pnt>();
126 return aMyPln.Distance(aPnt);
129 void GeomAPI_Pln::translate(const std::shared_ptr<GeomAPI_Dir> theDir, double theDist)
131 gp_Vec aVec(theDir->impl<gp_Dir>());
133 aVec.Multiply(theDist);
134 implPtr<gp_Pln>()->Translate(aVec);
137 std::shared_ptr<GeomAPI_Lin>
138 GeomAPI_Pln::intersect(const std::shared_ptr<GeomAPI_Pln> thePlane) const
140 std::shared_ptr<GeomAPI_Lin> aRes;
142 if(!thePlane.get()) {
146 const gp_Pln& aMyPln = impl<gp_Pln>();
147 const gp_Pln& anOtherPln = thePlane->impl<gp_Pln>();
149 IntAna_QuadQuadGeo aQuad(aMyPln, anOtherPln, Precision::Confusion(), Precision::Confusion());
151 if(aQuad.IsDone() != Standard_True) {
155 if(aQuad.NbSolutions() != 1) {
159 gp_Lin aLin = aQuad.Line(1);
160 gp_Pnt aLoc = aLin.Location();
161 gp_Dir aDir = aLin.Direction();
163 std::shared_ptr<GeomAPI_Pnt> aGeomLoc(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
164 std::shared_ptr<GeomAPI_Dir> aGeomDir(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
166 aRes.reset(new GeomAPI_Lin(aGeomLoc, aGeomDir));