English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriel de base Java

Contrôle de flux Java

Java Tableau

Java Programmation orientée objet (I)

Java Programmation orientée objet (II)

Java Programmation orientée objet (III)

Gestion des exceptions Java

Java Liste (List)

Java Queue (file d'attente)

Java Map de collections

Java Set de collections

Java Entrée/sortie (I/)

Java Reader/Writer

Autres sujets Java

Java Math atan2Méthode d'utilisation et exemple ()

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.

atan2paramètres

  • x / y-Right-angle coordinates x and y

NoteThe coordinates x and y represent points in a two-dimensional plane.

atan2() return value

  • By returning the coordinate(x, y)Convert to coordinates(r, θ)Returns the angle θ

Example: Java Math.atan2()

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 θ.

Java Math Mathematical Methods