Java Angle Calculate angleOf(Point2D a, Point2D b)

Here you can find the source of angleOf(Point2D a, Point2D b)

Description

Calculates the radian angle from point a to point b .

License

LGPL

Parameter

Parameter Description
a The reference point.
b Another point in the space.

Return

The radian angle from point a to point b.

Declaration

public static double angleOf(Point2D a, Point2D b) 

Method Source Code

//package com.java2s;
/**/*w  ww .j av  a 2s  .c  o m*/
 * Computes the intersection between two lines. The calculated point is approximate, 
 * since integers are used. If you need a more precise result, use doubles
 * everywhere. 
 * (c) 2007 Alexander Hristov. Use Freely (LGPL license). http://www.ahristov.com
 *
 * @param x1 Point 1 of Line 1
 * @param y1 Point 1 of Line 1
 * @param x2 Point 2 of Line 1
 * @param y2 Point 2 of Line 1
 * @param x3 Point 1 of Line 2
 * @param y3 Point 1 of Line 2
 * @param x4 Point 2 of Line 2
 * @param y4 Point 2 of Line 2
 * @return Point where the segments intersect, or null if they don't
 */

import java.awt.geom.Point2D;

public class Main {
    /**
     * Calculates the radian angle from point a to point b .
     * @param a The reference point.
     * @param b Another point in the space.
     * @return The radian angle from point a to point b.
     */
    public static double angleOf(Point2D a, Point2D b) {
        // Calculate angle from a to b
        double x = b.getX() - a.getX();
        double y = b.getY() - a.getY();
        return Math.atan2(y, x);
    }
}

Related

  1. angle(Point2D from, Point2D to)
  2. angle(Point2D.Double vec)
  3. angle2D(Point p1, Point p2)
  4. angleBetween(Point2D.Double vec1, Point2D.Double vec2)
  5. anglePI(Point2D top, Point2D corner1, Point2D corner2)
  6. angleToPoint(Rectangle r, double angle)
  7. calculateAngle(double dx, double dy)
  8. calculateAngle(float x, float y, float x1, float y1)