StrictMath atan2() Method in Java

The java.lang.StrictMath.atan2() is an inbuilt method in java which is used to calculate arc tangent of ordinate_val/abscissa_val in the range between -pi and pi. It returns the angle from the conversion of rectangular coordinates (abscissa_val, ordinate_val) to polar coordinates (p, angle).

  • The result is the double value closest to -pi when the abscissa_val is negative zero and the ordinate_val is negative, or the abscissa_val is negative and finite and the ordinate_val is negative infinity.
  • The result is the double value closest to pi/4 when both arguments are positive infinity.
  • The result is NaN when either argument is NaN.
  • The result is positive zero when the abscissa_val is positive zero and the ordinate_val is positive, or the abscissa_val is positive and finite and the ordinate_val is positive infinity.
  • The result is negative zero when the abscissa_val is negative zero and the ordinate_val is positive, or the abscissa_val is negative and finite and the ordinate_val is positive infinity.
  • The result is the double value closest to pi when the abscissa_val is positive zero and the ordinate_val is negative, or the abscissa_val is positive and finite and the ordinate_val is negative infinity.
  • The result is the double value closest to pi/2 when the abscissa_val is positive and the ordinate_val is positive zero or negative zero, or the abscissa_val is positive infinity and the ordinate_val is finite.
  • The result is the double value closest to -pi/2 when the abscissa_val is negative and the ordinate_val is positive zero or negative zero, or the abscissa_val is negative infinity and the ordinate_val is finite.
  • The result is the double value closest to pi/4 when both arguments are positive infinity.
  • The result is the double value closest to 3*pi/4 when the abscissa_val is positive infinity and the ordinate_val is negative infinity.
  • The result is the double value closest to -pi/4 when the abscissa_val is negative infinity and the ordinate_val is positive infinity.
  • The result is the double value closest to -3*pi/4 when both arguments are negative infinity.

Syntax :

public static double atan2(double abscissa_val, double ordinate_val )

Parameters: The method accepts two parameters:



  • ordinate_val: This is of double type which is the ordinate.
  • abscissa_val:This is of double type which is the abscissa.

Return Value: The method returns the theta component of the point (p, angle) in polar coordinates that corresponds to the point (abscissa_val,ordinate_val).

Below programs illustrate the java.lang.StrictMath.atan2() method:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java praogram to illustrate the
// java.lang.StrictMath.atan2()
  
import java.lang.*;
  
public class Geeks{
  
public static void main(String[] args) {
  
    double abs_val = 0.3 , ord_val = 50.00;
      
    // It returns the theta component 
    // in polar coordinates 
    double atan2val = StrictMath.atan2(abs_val,
                                          ord_val); 
    System.out.println("Arc tangent value is: "
                                        +atan2val);
  
}
}

chevron_right


Output:

Arc tangent value is: 0.00599992800155516

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java praogram to illustrate the
// java.lang.StrictMath.atan2()
  
import java.lang.*;
  
public class Geeks{
  
public static void main(String[] args) {
  
    double abs_val = 0.3 , ord_val = -50.00;
      
    // It returns the theta component 
    // in polar coordinates 
  
    double atan2val = StrictMath.atan2(abs_val,
                                          ord_val); 
    System.out.println("Arc tangent value is: "
                                        +atan2val);
  
}
}

chevron_right


Output:

Arc tangent value is: 3.135592725588238

Program 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java praogram to illustrate the
// java.lang.StrictMath.atan2()
  
import java.lang.*;
  
public class Geeks{
  
public static void main(String[] args) {
  
    double abs_val = -0.3 ,ord_val = 50.00;
      
    // It returns the theta component 
    // in polar coordinates 
  
    double atan2val = StrictMath.atan2(abs_val,
                                          ord_val); 
    System.out.println("Arc tangent value is: "
                                        +atan2val);
  
}
}

chevron_right


Output:

Arc tangent value is: -0.00599992800155516

Program 4:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java praogram to illustrate the
// java.lang.StrictMath.atan2()
  
import java.lang.*;
  
public class Geeks{
  
public static void main(String[] args) {
  
    double abs_val = -0.3 , ord_val = -50.00;
      
    // It returns the theta component 
    // in polar coordinates 
  
    double atan2val = StrictMath.atan2(abs_val,
                                          ord_val); 
    System.out.println("Arc tangent value is: "
                                        +atan2val);
  
}
}

chevron_right


Output:

Arc tangent value is: -3.135592725588238


My Personal Notes arrow_drop_up

lets make it a lil simple

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.