Here you can find the source of anglePI(Point2D top, Point2D corner1, Point2D corner2)
Parameter | Description |
---|---|
top | The top of the angle. |
corner1 | The left corner point of the angle. |
corner2 | The right corner point of the angle. |
public static final double anglePI(Point2D top, Point2D corner1, Point2D corner2)
//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))); } }