Here you can find the source of angleBetweenPoints(double ax, double ay, double bx, double by)
public static double angleBetweenPoints(double ax, double ay, double bx, double by)
//package com.java2s; //License from project: Apache License public class Main { public static double angleBetweenPoints(double ax, double ay, double bx, double by) { double angle = 0; if (bx - ax == 0) { if (by > ay) angle = -90;//from w ww.j a v a 2 s . c o m else angle = 90; } else angle = Math.atan((by - ay) / (bx - ax)) * 180.0 / Math.PI; if (bx > ax) { if (by < ay) angle = 360 + angle; } else { if (by >= ay) angle = 180 + angle; else angle += 180; } return angle; } }