Here you can find the source of computeAngleRAD(@Nonnull Point2D p)
Parameter | Description |
---|---|
p | the vector (point relative to zeroPoint2D) |
@CheckReturnValue public static double computeAngleRAD(@Nonnull Point2D p)
//package com.java2s; //License from project: Open Source License import java.awt.geom.Point2D; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; public class Main { /**//from ww w .j a v a 2 s .c o m * compute the angle (direction in radians) for a vector * * @param p the vector (point relative to zeroPoint2D) * @return the angle in radians */ @CheckReturnValue public static double computeAngleRAD(@Nonnull Point2D p) { return Math.atan2(p.getX(), p.getY()); } /** * compute the angle (direction in radians) from point 1 to point 2 * <p> * Note: Goes CCW from south to east to north to west, etc. * For JMRI subtract from PI/2 to get east, south, west, north * * @param p1 the first Point2D * @param p2 the second Point2D * @return the angle in radians */ @CheckReturnValue public static double computeAngleRAD(@Nonnull Point2D p1, @Nonnull Point2D p2) { return computeAngleRAD(subtract(p1, p2)); } /** * subtract two points * * @param pA the first point * @param pB the second point * @return the difference of the two points */ @CheckReturnValue public static Point2D subtract(@Nonnull Point2D pA, @Nonnull Point2D pB) { return new Point2D.Double(pA.getX() - pB.getX(), pA.getY() - pB.getY()); } }