fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.awt.Point;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void rotate_point(Point p)
  12. {
  13. // random b value between -0.1 and +0.1 radians. You need to adjust these values.
  14. double b = -0.1 + 0.2 * (new Random().nextDouble());
  15. double cosb = Math.cos(b), sinb = Math.sin(b);
  16.  
  17. double newX = p.getX() * cosb - p.getY() * sinb;
  18. double newY = p.getY() * cosb + p.getX() * sinb;
  19.  
  20. p.setLocation( newX, newY );
  21. }
  22.  
  23. public static void main (String[] args) throws java.lang.Exception
  24. {
  25. Point p = new Point(125,125);
  26.  
  27. rotate_point(p);
  28.  
  29. System.out.println("p has moved from (125,125) to "+p);
  30. }
  31. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
p has moved from (125,125) to java.awt.Point[x=123,y=127]