Java Geometry Algorithm computeAngleRAD(@Nonnull Point2D p)

Here you can find the source of computeAngleRAD(@Nonnull Point2D p)

Description

compute the angle (direction in radians) for a vector

License

Open Source License

Parameter

Parameter Description
p the vector (point relative to zeroPoint2D)

Return

the angle in radians

Declaration

@CheckReturnValue
public static double computeAngleRAD(@Nonnull Point2D p) 

Method Source Code

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

Related

  1. circleLineIntersection(double theta, double r, double h, double k, Point2D[] result)
  2. clacGradient(Point2D p1, Point2D p2, Point2D p3)
  3. cleanList(List blueList, Polygon borders)
  4. colinearPoint(Line2D line, Point2D point, double distance)
  5. computeAngleDEG(@Nonnull Point2D p1, @Nonnull Point2D p2)
  6. computeBarycenter(Map values)
  7. computeEuclideanDistance(Point2D point1, Point2D point2)
  8. computePolygonArea(Point2D[] pts)
  9. coordinateSplit(Point2D.Double[] aPoints, double[] aX, double[] aY)