Java Angle from Point getAngleForPoint(Arc2D arc, int x, int y)

Here you can find the source of getAngleForPoint(Arc2D arc, int x, int y)

Description

get Angle For Point

License

Open Source License

Declaration

public static double getAngleForPoint(Arc2D arc, int x, int y) 

Method Source Code

//package com.java2s;
/*/* w w  w .  j a v  a 2s.c  om*/
 * Copyright (c) Leuville Objects All Rights Reserved.
 *
 * Leuville Objects MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. Leuville Objects SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

import java.awt.geom.*;

public class Main {
    public static double getAngleForPoint(Arc2D arc, int x, int y) {
        double px = x - arc.getCenterX();
        double py = arc.getCenterY() - y;
        double d = Math.sqrt(px * px + py * py);
        double a1 = Math.toDegrees(Math.acos(px / d));
        double a2 = Math.toDegrees(Math.asin(py / d));
        if (a2 < 0) {
            if (a1 > 90)
                return 360 - a1;
            else
                return -a1;
        } else
            return a1;
    }
}

Related

  1. getAngle(Point2D center, Point2D point)
  2. getAngle(Point2D origin, Point2D target)
  3. getAngle(Point2D p1, Point2D p2)
  4. getAngle(Point2D startPosition, Point2D endPosition)
  5. getAngle(Point2D.Double vertPt, Point2D.Double edgePt)