Guest User

Untitled

a guest
Aug 25th, 2019
84
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. double dist(double x, double y, int i) {
  3. if ((a[i].x0 - a[i].x1) * (x - a[i].x1) + (a[i].y0 - a[i].y1) * (y - a[i].y1) <= 0) {
  4. return sqr(x - a[i].x1) + sqr(y - a[i].y1);
  5. }
  6. if ((a[i].x1 - a[i].x0) * (x - a[i].x0) + (a[i].y1 - a[i].y0) * (y - a[i].y0) <= 0) {
  7. return sqr(x - a[i].x0) + sqr(y - a[i].y0);
  8. }
  9. double s = (a[i].x0 - x) * (a[i].y1 - y) - (a[i].x1 - x) * (a[i].y0 - y);
  10. return sqr(s) / (sqr(a[i].x0 - a[i].x1) + sqr(a[i].y0 - a[i].y1));
  11. }
RAW Paste Data