Salome HOME
6.12.2013.Fix of HasIntersection method.
[modules/hydro.git] / src / HYDROData / HYDROData_ProfileUZ.cxx
index d8ccba4e236cad9d0652b775da8e489342ec95bc..80fe9987309b306ecf9dc7ac997a2718e8577ec7 100755 (executable)
@@ -4,6 +4,7 @@
 #include "HYDROData_Tool.h"
 
 #include <gp_XY.hxx>
+#include <gp_Pnt2d.hxx>
 
 #include <TColStd_ListIteratorOfListOfReal.hxx>
 
@@ -30,6 +31,42 @@ TopoDS_Shape HYDROData_ProfileUZ::GetShape()
   return TopoDS_Shape();
 }
 
+double HYDROData_ProfileUZ::GetDepthFromDistance( const double& theDistance ) const
+{
+  double aResDepth = 0.0;
+
+  HYDROData_IPolyline::PointsList aPoints = GetPoints();
+  int aNbPoints = aPoints.Size();
+  if ( aNbPoints < 2 )
+    return aResDepth;
+
+  double aCompDist = 0.0;
+  HYDROData_IPolyline::Point aPrevPoint = aPoints.First();
+  for ( int i = 2; i <= aNbPoints; ++i )
+  {
+    const Point& aCurPoint = aPoints.Value( i );
+
+    double aPntDist = gp_Pnt2d( aPrevPoint.X(), 0 ).Distance( gp_Pnt2d( aCurPoint.X(), 0 ) );
+
+    aCompDist += aPntDist;
+
+    if ( theDistance < aCompDist )
+    {
+      double aComPntDist = gp_Pnt2d( aPoints.First().X(), 0 ).Distance( gp_Pnt2d( aPrevPoint.X(), 0 ) );
+
+      double aFindDist = theDistance - aComPntDist;
+      double aRatio = aFindDist / ( aPntDist - aFindDist );
+
+      aResDepth = ( aPrevPoint.Y() + aRatio * aCurPoint.Y() ) / ( 1 + aRatio );
+      break;
+    }
+
+    aPrevPoint = aCurPoint;
+  }
+
+  return aResDepth;
+}
+
 int HYDROData_ProfileUZ::NbSections() const
 {
   return 1;