Languages
[Edit]
EN

C# / .NET - Math.Atan2() method example

0 points
Created by:
Dharman
518

The Math.Atan2() function returns the angle in radians in the range -Math.PI/2 to +Math.PI/2 between the positive x-axis and the ray to the point (x, y) ≠ (0, 0).

Atan2() method has been visualized on below image:

atan2(y, x) function visualization - C# Math Object.
Atan2(y, x) function visualization - C# Math Object.

1. Documentation

Edit
Syntax
Parametersy, x - double values that are coordinates of the point (primitive value).
Result

number value of angle between two lines OP and OX in radians in the range -Math.PI/2 to +Math.PI/2 (primitive value).

Where:

  • O=(0, 0) - intersection point of coordinate system axes,
  • P=(x, y) - out point,
  • OX - positive part of x-axis.

If point is in the 1st (I) or 2nd (II) quadrant angle is measured in a counterclockwise direction.

If point is in the 3rd (III) or 4th (IV) quadrant angle is measured in a clockwise direction.

Note: angle arrows show measured angles for points located in different quadrants.

Description

Atan2 is a static method that takes two parameters and returns an approximation of the arctangent(y/x) function taking into account quadrants of a point location (P=(x, y)).

2. Working with degrees

Edit

3.  Conversion to only clockwise angles in degrees

Edit

This section shows how to convert angles to clockwise angles (from 0 to 360 degrees).

4.  Conversion to only counterclockwise angles in degrees

Edit

This section shows how to convert angles to counterclockwise angles (from -360 to 0 degrees).

References

Edit
  1. atan2 - Wikipedia
  2. Inverse trigonometric functions - Wikipedia
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

C# / .NET - Math object

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join