Here you can find the source of angleOfLineDeg(double x1, double y1, double x2, double y2)
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. |
public static double angleOfLineDeg(double x1, double y1, double x2, double y2)
//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; } }