Java Angle Calculate angle2D(Point p1, Point p2)

Here you can find the source of angle2D(Point p1, Point p2)

Description

angle D

License

Open Source License

Declaration

public static double angle2D(Point p1, Point p2) 

Method Source Code


//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;
    }
}

Related

  1. angle(Point2D from, Point2D to)
  2. angle(Point2D.Double vec)
  3. angleBetween(Point2D.Double vec1, Point2D.Double vec2)
  4. angleOf(Point2D a, Point2D b)
  5. anglePI(Point2D top, Point2D corner1, Point2D corner2)
  6. angleToPoint(Rectangle r, double angle)