Java Utililty Methods Angle Calculate

List of utility methods to do Angle Calculate

Description

The list of methods to do Angle Calculate are organized into topic(s).

Method

doubleangle(Point2D from, Point2D to)
angle
Point2D delta = subtract(from, to);
return Math.atan2(delta.getY(), delta.getX());
doubleangle(Point2D.Double vec)
Computes "angle" of a vector using the Math.atan method.
if (Double.isInfinite(vec.x)) {
    return vec.y > PI ? vec.y - 2 * PI : vec.y;
return atan2(vec.y, vec.x);
doubleangle2D(Point p1, Point p2)
angle D
double dtheta = Math.atan2(p2.y, p2.x) - Math.atan2(p1.y, p1.x);
while (dtheta > Math.PI) {
    dtheta -= 2.0 * Math.PI;
while (dtheta < -1.0 * Math.PI) {
    dtheta += 2.0 * Math.PI;
return dtheta;
...
doubleangleBetween(Point2D.Double vec1, Point2D.Double vec2)
Computes angle between two vectors, as comptued by the dot product formula
return Math.acos(dotProduct(vec1, vec2) / (magnitude(vec1) * magnitude(vec2)));
doubleangleOf(Point2D a, Point2D b)
Calculates the radian angle from point a to point b .
double x = b.getX() - a.getX();
double y = b.getY() - a.getY();
return Math.atan2(y, x);
doubleanglePI(Point2D top, Point2D corner1, Point2D corner2)
Calculate the value of the angle [0,PI).
double x1 = corner1.getX() - top.getX();
double x2 = corner2.getX() - top.getX();
double y1 = corner1.getY() - top.getY();
double y2 = corner2.getY() - top.getY();
return Math.acos((x1 * x2 + y1 * y2) / Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2)));
PointangleToPoint(Rectangle r, double angle)
angle To Point
double si = Math.sin(angle);
double co = Math.cos(angle);
double e = 1.0E-4D;
int x = 0;
int y = 0;
if (Math.abs(si) > e) {
    x = (int) ((1.0D + co / Math.abs(si)) / 2.0D * (double) r.width);
    x = range(0, r.width, x);
...
doublecalculateAngle(double dx, double dy)
calculate Angle
double alpha;
if (Math.abs(dx) > Math.abs(dy)) {
    double tg = dy / dx;
    alpha = Math.atan(tg);
    if (dx < 0) {
        alpha += Math.PI;
} else {
...
floatcalculateAngle(float x, float y, float x1, float y1)
From x,y -> x1,y1
double angle = Math.atan2(y - y1, x - x1);
return (float) angle + 1.5f;
doublecalculateAngle(int a1, int b1, int a2, int b2)
Calculates the angle between two points in 2D space
double distance_between_a1_a2 = calculateDifference(a1, a2);
double distance_between_b1_b2 = calculateDifference(b1, b2);
return Math.atan(distance_between_b1_b2 / distance_between_a1_a2);