Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Point selectPoint(int xp, int yp) {
- double x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
- //step 1: wide x, set y
- x1 = (double) xp * (double) y0 / (double) x0;
- y1 = (double) yp;
- //step2: rotate 45° CCW
- y2 = x1;
- x2 = -y1;
- //step3: round
- double base = y0 * Math.pow(2, 1 / 2);
- x3 = base * Math.round(x2 / base);
- y3 = base * Math.round(y2 / base);
- //step4: rotate 45° CW
- x4 = y3;
- y4 = -x3;
- //step5: un-wide x, copy y
- x5 = x4 * (double) x0 / (double) y0;
- y5 = y4;
- //final step: return
- return new Point((int) Math.round(x5), (int) Math.round(y5));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement