Java Angle from Point getAngle(Point2D origin, Point2D target)

Here you can find the source of getAngle(Point2D origin, Point2D target)

Description

get Angle

License

Open Source License

Declaration

public static double getAngle(Point2D origin, Point2D target) 

Method Source Code

//package com.java2s;
/*/* ww w.ja v a2s .c o m*/
 * Copyright (c) 2014 tabletoptool.com team.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     rptools.com team - initial implementation
 *     tabletoptool.com team - further development
 */

import java.awt.geom.Point2D;

public class Main {
    public static double getAngle(Point2D origin, Point2D target) {

        double angle = Math.toDegrees(Math.atan2((origin.getY() - target.getY()), (target.getX() - origin.getX())));
        if (angle < 0) {
            angle += 360;
        }

        return angle;
    }
}

Related

  1. getAngle(double originX, double originY, double x, double y)
  2. getAngle(Point2D center, Point2D point)
  3. getAngle(Point2D p1, Point2D p2)
  4. getAngle(Point2D startPosition, Point2D endPosition)
  5. getAngle(Point2D.Double vertPt, Point2D.Double edgePt)
  6. getAngleForPoint(Arc2D arc, int x, int y)