Guest User

Untitled

a guest
Dec 11th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. public int getDistance(string id, string von, string zu)
  2. {
  3. QueryReader qr = new QueryReader(db, "select t.x, t.y from stdortboote b, table (sdo_util.getvertices(b.shape)) t " +
  4. "where b.idboot = " + id + " and b.datum between to_date('" + von + "', 'DD.MM.YYYY HH24:MI') and to_date('" + zu + "', 'DD.MM.YYYY HH24:MI')");
  5. double dist = 0;
  6. if (qr.Open())
  7. {
  8. int i = 0;
  9. double lx = 0, ly = 0;
  10.  
  11. //performance
  12. while (qr.Read())
  13. {
  14. int _x = qr.OracleReader.GetInt32(0);
  15. int _y = qr.OracleReader.GetInt32(1);
  16.  
  17. double tx = _x;
  18. double ty = _y;
  19.  
  20. //
  21. // this makes sense if you think about it
  22. // calc distance between to points
  23. //
  24. // (x1,y1)
  25. // /
  26. // /
  27. // (x0, y0)
  28. //
  29. // so dist = sqrt((x1-x0)^2 + (y1-y1)^2)
  30. //
  31.  
  32. if (i % 2 == 0)
  33. {
  34. if (i > 0)
  35. {
  36. double delta = Math.Sqrt(Math.Pow(tx - lx, 2) + Math.Pow(ty - ly, 2));
  37. dist += delta;
  38. }
  39. lx = tx;
  40. ly = ty;
  41. }
  42. else
  43. {
  44. double delta = Math.Sqrt(Math.Pow(tx - lx, 2) + Math.Pow(ty - ly, 2));
  45. dist += delta;
  46. lx = tx;
  47. ly = ty;
  48. //MessageBox.Show(delta + " --> " + dist);
  49. }
  50.  
  51. i++;
  52. }
  53.  
  54. qr.Close();
  55. }
  56.  
  57. return (int)(dist*100);
  58. }
Add Comment
Please, Sign In to add comment