Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

atan2()

Example

Provide the angle in radians corresponding to the polar coordinates derived from the given rectangular coordinates.

System.out.println(Math.atan2(0.5, 0.5));
System.out.println(Math.atan2(-0.5, -0.5));
System.out.println(Math.atan2(5, 5));
System.out.println(Math.atan2(10, 20));
System.out.println(Math.atan2(-5, -5));
System.out.println(Math.atan2(-10, 10));

Definition and Usage

The atan2() function computes the angle theta in radians by converting rectangular coordinates (x, y) to polar coordinates (r, theta).

It’s equivalent to atan(y/x), but it accommodates negative x values, allowing for angles beyond the range of -π/2 to π/2.

Note: In the atan2() method, the y coordinate precedes the x coordinate, as it performs the division y / x.

Syntax

public static double atan2(double y, double x)

Parameter Values

Parameter

Description

y

The input required is the y-coordinate of the point for which the angle is to be determined.

x

The input required is the x-coordinate of the point for which the angle is to be determined.

Technical Details

Returns

It returns a double value representing the angle in radians that a point (x, y) forms around the origin (0, 0).

Java Version

Any