Here you can find the source of angleFromDirection(float dirX, float dirY)
public static float angleFromDirection(float dirX, float dirY)
//package com.java2s; public class Main { public static float angleFromDirection(float dirX, float dirY) { if (dirX == 0f) { return 0f; }//from w w w . j a v a2s . com float inv = dirY / dirX; float ang = (float) Math.atan(inv); // Extra half rotation if we're past 180 if (dirX < 0) { ang += (float) Math.PI; } // Offset so that angle of 0 is straight up ang -= (float) Math.PI * 0.5f; return ang; } }