Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. double
  2. calculate_distance(point_xy* query, rtr_mbr_t* targetmbr) /*Starting with just a mbr and a fixed point to make the calculations*/
  3. //calculate_distance(const Geometry *query, const MBR *target)
  4. {
  5. double mindist= 0;
  6.  
  7. //Distance inside a mbr
  8. if ((query->x > targetmbr->xmin) && (query->x < targetmbr->xmax) && (query->y > targetmbr->ymin) && (query->y < targetmbr->ymax))
  9. {
  10. return 0;
  11. }
  12. // Distance to a point
  13. if (targetmbr->xmax == targetmbr->xmin && targetmbr->ymin ==targetmbr->ymax)
  14. {
  15. mindist = sqrt((pow((targetmbr->xmax -query->x), 2))+(pow((targetmbr->ymax - query->y), 2))); //xy-max
  16.  
  17. }
  18.  
  19. else
  20. {
  21. double qp1p2= linesegment_distance(query, targetmbr->xmin, targetmbr->xmax, targetmbr->ymin, targetmbr->ymin);
  22.  
  23. double qp2p3= linesegment_distance(query, targetmbr->xmax, targetmbr->xmax, targetmbr->ymin, targetmbr->ymax);
  24.  
  25. double qp3p4= linesegment_distance(query, targetmbr->xmax, targetmbr->xmin, targetmbr->ymax, targetmbr->ymax);
  26.  
  27. double qp4p1= linesegment_distance(query, targetmbr->xmin, targetmbr->xmin, targetmbr->ymax, targetmbr->ymin);
  28.  
  29. double minlinedist= (qp1p2 < qp2p3)? qp1p2 : qp2p3;
  30. double minlinedist1= (qp3p4 < qp4p1)? qp3p4 : qp4p1;
  31. double mindist = (minlinedist < minlinedist1)? minlinedist : minlinedist1;
  32.  
  33. //Compare and return the smallest distance
  34. // mindist = (dist1 < dist0)? dist1 : dist0;
  35. }
  36.  
  37.  
  38. return mindist;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement