Why aren't there asin2 () and acos2 () functions similar to atan2 ()?

In my opinion, the atan2() function exists in programming languages ​​because atan() itself cannot always determine the correct theta, since the output is limited to -pi / 2 to pi / 2.

If so, then the same problem applies to both asin() and acos() , both of which also have limited ranges, so why are there no functions asin2() and acos2() ?

+10
source share
3 answers

First, note that the syntax is atan(y/x) , but atan2(y, x) , not atan2(y/x) . This is important because, without performing the separation, you provide additional information, and most importantly, the individual signs x and y . If you know the x and y coordinates separately, you know the angle, including the quadrant.

If you go from tan(θ) = y/x to sin(θ) = y/sqrt(x²+y²) , then the inverse operation asin takes y and sqrt(x²+y²) and combines this to get some information about the angle . It doesn’t matter if we perform the separation ourselves or let some kind of hypothetical function asin2 handle it. The denominator is always positive, so a divided argument contains as much information as a separate numerator and denominator. (At least in an IEEE environment, where division by zero results in correctly signed infinity.)

If you know the coordinates y and hypothenuse sqrt(x²+y²) , then you know the sine of the angle, but you may not know the angle itself, since you can not distinguish between negative and positive values of x . Similarly, if you know the x coordinate and hypotenuse, you know the cosine of the angle, but you cannot know the sign of the y value.

So, asin2 and acos2 are not mathematically feasible, at least not in an obvious way. If you have some kind of sign encoded in the hypotenuse, everything may be different, but I can’t think of a situation where such a sign will arise naturally.

+10
source

I will explain in SIMPLY CONDITIONS as follows.
Refer to this image for the following explanation:

enter image description here

Task: select a function that will track the correct angle in the range -180 < θ < 180

Test 1: sin() positive in the first and second quadrants, sin(30) = sin(150) = 0.5 . Tracking a quadrant change with sin() will not be easy.

Therefore, asin2() not feasible.

Test 2: cos() positive in the first and fourth quadrants, cos(60) = sin(300) = 0.5 . In addition, it will not be easy to track the change in the quadrant with cos() .

Consequently, acos2() again is not feasible.

Test 3: tan() is positive in the first and third quadrants and in an interesting order.

It is positive in the 1st quadrant, negative in the 2nd, positive in the 3rd, negative in the 4th and positive in the wrapped -1th quadrant.

so tan(45) = 1 , tan(135) = -1 , tan(225) = 1 , tan(315) = -1 and tan(360+45) = 1 . Hurrah! we can track the quadrant change.

Note that the unambiguous range is -180 < θ < 180 . Also, note that in my example with a 45-degree increment above, if the sequence is 1,-1,.. angle goes counterclockwise, and if the sequence is -1,1,.. it goes clockwise. This idea should decide the direction.

Therefore, atan2() becomes our choice .

0
source

There are times when you need a function like "acos2", for example, when you rotate vectors in three-dimensional space. Under these conditions, I hard code my own acos2 function, which simply performs the following checks:

 x_perp=sqrt(x*x+y*y) r=sqrt(x*x+y*y+z*z) if(x_perp.gt.0.0d0) then phi=acos(x/x_perp) else phi=0.0d0 endif if(y.lt.0.0d0) phi=2.0d0*pi-phi theta=acos(z/r) 

where theta and phi are ordinary spherical coordinates, and x, y, z are Cartesian coordinates. The problem arises when y is negative, there must be a phase shift in phi. There is no such problem for theta.

0
source

Source: https://habr.com/ru/post/1215513/


All Articles