Here you can find the source of angle2D(Point p1, Point p2)
public static double angle2D(Point p1, Point p2)
//package com.java2s; //License from project: Open Source License import java.awt.*; public class Main { public static double angle2D(Point p1, Point p2) { double dtheta = Math.atan2(p2.y, p2.x) - Math.atan2(p1.y, p1.x); while (dtheta > Math.PI) { dtheta -= 2.0 * Math.PI; }/*from w ww.j a v a 2 s. c o m*/ while (dtheta < -1.0 * Math.PI) { dtheta += 2.0 * Math.PI; } return dtheta; } }