Advertisement
kajacx

Kosoctverce

Sep 17th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. public Point selectPoint(int xp, int yp) {
  2.             double x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
  3.             //step 1: wide x, set y
  4.             x1 = (double) xp * (double) y0 / (double) x0;
  5.             y1 = (double) yp;
  6.  
  7.             //step2: rotate 45° CCW
  8.             y2 = x1;
  9.             x2 = -y1;
  10.  
  11.             //step3: round
  12.             double base = y0 * Math.pow(2, 1 / 2);
  13.             x3 = base * Math.round(x2 / base);
  14.             y3 = base * Math.round(y2 / base);
  15.  
  16.             //step4: rotate 45° CW
  17.             x4 = y3;
  18.             y4 = -x3;
  19.  
  20.             //step5: un-wide x, copy y
  21.             x5 = x4 * (double) x0 / (double) y0;
  22.             y5 = y4;
  23.  
  24.             //final step: return
  25.             return new Point((int) Math.round(x5), (int) Math.round(y5));
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement