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

Tutorial Básico de Java

Controle de fluxo Java

Java Array

Java Orientação a Objetos (I)

Java Orientação a Objetos (II)

Java Orientação a Objetos (III)

Tratamento de Exceção do Java

Java Lista (List)

Java Fila (Queue)

Java Mapa (Map)

Java Conjunto (Set)

Java Entrada e Saída (I/)

Java Reader/Writer

Outros tópicos do Java

Java Math atan2Uso do método e exemplo

Java Math Mathematical Methods

Java Math atan2O método converte as coordenadas cartesianas (x, y) em coordenadas polares (r, θ) e retorna o ângulo theta (θ).

: The coordinates x and y represent a point in the two-dimensional plane.2A sintaxe do método é:

Math.atan2(double y, double x)

Right-angled coordinates x and yatan2O método estático. Portanto, podemos chamar diretamente o método usando o nome da classe Math.

: The coordinates x and y represent a point in the two-dimensional plane.2parâmetros

  • x / y-直角坐标x和y

Right-angled coordinates x and yNote

: The coordinates x and y represent a point in the two-dimensional plane.2atan

  • By returning the value of coordinates(x,y)Convert to coordinates(r, θ)Return 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 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 an angle to angle θ.

Java Math Mathematical Methods