Here you can find the source of angleOf(Point2D a, Point2D b)
Parameter | Description |
---|---|
a | The reference point. |
b | Another point in the space. |
public static double angleOf(Point2D a, Point2D b)
//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); } }