Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - atan2() method



The atan2() method converts rectangular coordinates (x, y) to polar coordinate (r, theta) and returns theta.

Syntax

double atan2(double y, double x)

Parameters

  • x − X co-ordinate in double data type.

  • y − Y co-ordinate in double data type.

Return Value

This method returns theta from polar coordinate (r, theta).

Example - Usage of atan2() method for a positive double values

Following is an example of the usage of this method −

Example.groovy

class Example {     
   static void main(String[] args){
      double x = 45.0;
      double y = 30.0;
		
      println( Math.atan2(x, y) );
   } 
}

Output

When we run the above program, we will get the following result −

0.982793723247329

Example - Usage of atan2() method for zero double values

Following is an example of the usage of this method −

Example.groovy

class Example { 
   static void main(String[] args) { 
      double x = 0.0;
      double y = 0.0;
		
      println( Math.atan2(x, y) );
   }
}

Output

When we run the above program, we will get the following result −

0.0

Example - Usage of atan2() method for negative double values

Following is an example of the usage of this method −

Example.groovy

class Example { 
   static void main(String[] args) { 
      double x = -45.0;
      double y = -30.0;
		
      println( Math.atan2(x, y) );
   }
}

Output

When we run the above program, we will get the following result −

-2.1587989303424644
groovy_numbers.htm
Advertisements