Java Angle angleOfLineDeg(double x1, double y1, double x2, double y2)

Here you can find the source of angleOfLineDeg(double x1, double y1, double x2, double y2)

Description

Determines the angle at which a line must be drawn to get from the first point to the second in degrees.

License

Open Source License

Parameter

Parameter Description
x1 The X coordinate of the first point.
y1 The Y coordinate of the first point.
x2 The X coordinate of the second point.
y2 The Y coordinate of the second point.

Return

The angle of a line from the first point to the second in degrees.

Declaration

public static double angleOfLineDeg(double x1, double y1, double x2, double y2) 

Method Source Code

//package com.java2s;
/*//from   w w  w  .j  a  va2s  .co m
 * Copyright (C) 2014  Sina Ghaffari (sina.ghaffari@mail.utoronto.ca) & Tristan Homsi (thomsi@uwaterloo.ca)
 * 
 * This file is part of Simple2D.
    
 * Simple2D 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 3 of the License, or
 * (at your option) any later version.
 *
 * Simple2D 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 Simple2D.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Determines the angle at which a line must be drawn to get from the first
     * point to the second in degrees.
     *
     * @param x1 The X coordinate of the first point.
     * @param y1 The Y coordinate of the first point.
     * @param x2 The X coordinate of the second point.
     * @param y2 The Y coordinate of the second point.
     * @return The angle of a line from the first point to the second in
     * degrees.
     */
    public static double angleOfLineDeg(double x1, double y1, double x2, double y2) {
        double t = Math.toDegrees(Math.atan2((y2 - y1), (x2 - x1)));
        return (t < 0) ? t + 360 : t;
    }
}

Related

  1. angleInRadians(float originX, float originY, float targetX, float targetY)
  2. angleInRange(double angle, double min, double max)
  3. angleInRange(float theta1, float theta2, float tolerance)
  4. angleLinear(float a, float b, int spin, float f)
  5. angleOfLine(int x1, int y1, int x2, int y2)
  6. angleRadToDegClipped(final double angleRad)
  7. anglesInvalid(double sza, double vza, double saa, double vaa)
  8. angleSum(float a1, float a2)
  9. angleTo(final int x, final int y, final int thatx, final int thaty)