The difference between atan (y/x) and atan2 (y,x)

Source: Internet
Author: User

There are two functions to compute the tangent in the C + + standard library, one is Atan (y/x) and the other is atan2 (y, x).

Atan2 (y, x) is a 4 quadrant tangent, and its value depends not only on the tangent y/x, but also on which quadrant the point (x, y) falls into: When the point (x, y) falls into the first image limit, the atan2 (y, x) range is 0 ~ PI/2; When the point (x, y) falls into the second image limit, the range of atan2 (y, x) is PI/2 ~ Pi; When the point (x, y) falls into the third image limit, the range of atan2 (y, x) is-PI~-PI/2; When the point (x, y) falls into the four-image limit, the range of atan2 (y, x) is-pi/2~0.

and Atan (y/x) only according to the tangent of y/x to find the corresponding angle (can be seen as just 2 quadrant tangent): When the y/x > 0 o'clock, Atan (y/x) value range is 0 ~ PI/2; when y/x < 0 o'clock, Atan (y/x) value range is-pi/ 2~0.

So atan2 (y, x) = Atan (y/x) only occurs at the point (x, y) that falls into the first quadrant (x>0, y>0) or the fourth quadrant (X>0, y<0).

For example, suppose y = 1.0, X =-1.0, then Atan (y/x) = Atan ( -1.0) =-pi/4, and atan2 (y, x) = 3*pi/4.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.