Skip to content
Related Articles

Related Articles

StrictMath atan2() Method in Java

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 13 Dec, 2021

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:  

java




// Java program 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);
 
}
}

Output: 

Arc tangent value is: 0.00599992800155516

 

Program 2: 

java




// Java program 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);
 
}
}

Output: 

Arc tangent value is: 3.135592725588238

 

Program 3:  

java




// Java program 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);
 
}
}

Output: 

Arc tangent value is: -0.00599992800155516

 

Program 4: 

java




// Java program 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);
 
}
}

Output: 

Arc tangent value is: -3.135592725588238

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!