SHARE
TWEET

Untitled

a guest Aug 25th, 2019 79 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top