Java Angle Calculate anglePI(Point2D top, Point2D corner1, Point2D corner2)

Here you can find the source of anglePI(Point2D top, Point2D corner1, Point2D corner2)

Description

Calculate the value of the angle [0,PI).

License

Open Source License

Parameter

Parameter Description
top The top of the angle.
corner1 The left corner point of the angle.
corner2 The right corner point of the angle.

Return

The angle in radius.

Declaration

public static final double anglePI(Point2D top, Point2D corner1, Point2D corner2) 

Method Source Code


//package com.java2s;

import java.awt.geom.Point2D;

public class Main {
    /**//from w w  w.j av a 2  s. c  om
     * Calculate the value of the angle [0,PI). The angle is calculating
     * according to cosine theory.
     * 
     * @param top
     *            The top of the angle.
     * @param corner1
     *            The left corner point of the angle.
     * @param corner2
     *            The right corner point of the angle.
     * @return The angle in radius.
     */
    public static final double anglePI(Point2D top, Point2D corner1, Point2D corner2) {
        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)));
    }
}

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. angleOf(Point2D a, Point2D b)
  6. angleToPoint(Rectangle r, double angle)
  7. calculateAngle(double dx, double dy)
  8. calculateAngle(float x, float y, float x1, float y1)
  9. calculateAngle(int a1, int b1, int a2, int b2)