Java examples for java.lang:Math Geometry
converts cartesian coordinates (positive Y is down, positive X is right) into an angle in degrees (0 degrees is up, clockwise is positive).
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { int x = 2; int y = 2; System.out.println(toAngle(x, y)); }/*from w w w.j a va 2s . c o m*/ /** * converts cartesian coordinates (positive Y is down, positive X is right) * into an angle in degrees (0 degrees is up, clockwise is positive). The * angle is between 0 and 359, inclusive. * * @param x * @param y * @return */ public static int toAngle(int x, int y) { return (int) ((Math.toDegrees(Math.atan2(y, x)) + 90) % 360); } }