Java Angle Calculate angle(Point2D from, Point2D to)

Here you can find the source of angle(Point2D from, Point2D to)

Description

angle

License

Open Source License

Declaration

public static double angle(Point2D from, Point2D to) 

Method Source Code

//package com.java2s;
/* /*from w ww.  ja v a2  s .c  o m*/
    
 Created on Mar 4, 2005
    
 The Bungee View applet lets you search, browse, and data-mine an image collection.  
 Copyright (C) 2006  Mark Derthick
    
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.  See gpl.html.
    
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    
 You may also contact the author at 
 mad@cs.cmu.edu, 
 or at
 Mark Derthick
 Carnegie-Mellon University
 Human-Computer Interaction Institute
 Pittsburgh, PA 15213
    
 */

import java.awt.geom.Point2D;

public class Main {
    public static double angle(Point2D from, Point2D to) {
        Point2D delta = subtract(from, to);
        return Math.atan2(delta.getY(), delta.getX());
    }

    public static Point2D subtract(Point2D from, Point2D to) {
        return new Point2D.Double(to.getX() - from.getX(), to.getY() - from.getY());
    }
}

Related

  1. angle(Point2D.Double vec)
  2. angle2D(Point p1, Point p2)
  3. angleBetween(Point2D.Double vec1, Point2D.Double vec2)
  4. angleOf(Point2D a, Point2D b)