English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math Mathematical Methods
Java Math atan2La méthode () convertit les coordonnées cartésiennes spécifiées (x, y) en coordonnées polaires (r, θ) et retourne l'angle theta (θ).
atan2La syntaxe de la méthode () est :
Math.atan2(double y, double x)
Note:atan2La méthode () est une méthode statique. Par conséquent, nous pouvons appeler cette méthode directement en utilisant le nom de la classe Math.
x / y-Right-angle coordinates x and y
NoteThe coordinates x and y represent points in a two-dimensional plane.
By returning the coordinate(x, y)Convert to coordinates(r, θ)Returns the angle θ
class Main { public static void main(String[] args) { //two coordinates x and y double x = 3.7; double y = 6.45; //Get the angle θ double theta = Math.atan2(y, x); System.out.println(theta); // 1.0499821573815171 //Convert to degrees System.out.println(Math.toDegrees(theta)); // 60.15954618200191 } }
Here, atan2The () method converts coordinates(x, y) conversionfor coordinates(r, θ)and return the angle theta (θ).
We have usedMath.toDegrees()The method converts the angle to angle θ.