Salome HOME
Projection of outer edge onto the sketch plane (improvement #1297)
[modules/shaper.git] / src / GeomAPI / GeomAPI_Pln.cpp
index 4ba71589844abbf5e043c48076f5124325f121e5..347e994f4d4a98d3c1735678f5dc8d11e518c779 100644 (file)
@@ -74,3 +74,15 @@ std::shared_ptr<GeomAPI_Pnt> GeomAPI_Pln::intersect(const std::shared_ptr<GeomAP
   double aParam = aNormal->dot(aLocation->decreased(aLineLoc)) / aDot;
   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLineLoc->added(aLineDir->multiplied(aParam))));
 }
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Pln::project(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
+{
+  std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
+  std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
+
+  std::shared_ptr<GeomAPI_XYZ> aVec = thePoint->xyz()->decreased(aLocation);
+  double aDot = aNormal->dot(aVec);
+  std::shared_ptr<GeomAPI_XYZ> aProjection = 
+      aLocation->added(aVec->decreased(aNormal->multiplied(aDot)));
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aProjection));
+}