2015/11/10

Java 二維空間 求旋轉後的新座標


Code:
package test;

import java.awt.Point;

public class test {
 public static void main(String[] args) {
  Point point = new Point(2, 3);
  double degree = 90d;
  int[] array = getRotation(degree, point);
  System.out.printf("%d,%d\n", array[0], array[1]);

 }

 public static int[] getRotation(double degree, Point point) {
  int[] array = new int[2];
  double theda = degree * (Math.PI / 180d);
  array[0] = (int) (point.x * Math.cos(theda) - point.y * Math.sin(theda));
  array[1] = (int) (point.x * Math.sin(theda) + point.y * Math.cos(theda));
  return array;
 }
}