Java Angle Between angleBetweenPoints(double ax, double ay, double bx, double by)

Here you can find the source of angleBetweenPoints(double ax, double ay, double bx, double by)

Description

angle Between Points

License

Apache License

Declaration

public static double angleBetweenPoints(double ax, double ay, double bx, double by) 

Method Source Code

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

Related

  1. angleBetween(double[] v1, double[] v2)
  2. angleBetween(final double ax, final double ay, final double bx, final double by)
  3. angleBetween2Lines(double l1x1, double l1y1, double l1x2, double l1y2, double l2x1, double l2y1, double l2x2, double l2y2)
  4. angleBetween2LinesVectorAlgebra(double x11, double y11, double x12, double y12, double x21, double y21, double x22, double y22)
  5. AngleBetweenDegrees(double longitudeFirstBody, double latitudeFirstBody, double longitudeSecondBody, double latitudeSecondBody)
  6. AngleBetweenVectors(double X1, double Y1, double Z1, double X2, double Y2, double Z2)