POV-Ray : Newsgroups : povray.general : I have a problem with atan2() : Re: I have a problem with atan2() Server Time
20 Apr 2024 02:37:03 EDT (-0400)
  Re: I have a problem with atan2()  
From: Cousin Ricky
Date: 17 Oct 2021 17:46:33
Message: <616c99b9@news.povray.org>
On 2021-10-17 6:40 AM (-4), kurtz le pirate wrote:
> 
> I have a problem with  atan2(a,b) when b = zero.
> 
> The documentation on the page
> <http://www.povray.org/documentation/view/3.7.1/228/> says :
> 
> Arc-tangent of (A/B). Returns the angle, measured in radians, whose
> tangent is (A/B). **Returns appropriate value even if B is zero**
> 
> In my case, i get : Parse Error: Domain error in atan2!

Is your value for A also zero?

> So it's up to me to test if b=zero and return the appropriate value ?

It seems that some people are confused about atan2().

Of course, the inverse tangent of A/0 is undefined, because A/0 is
undefined.  But a simple limits exercise, as well as the very definition
of the tangent of an angle, show that these undefined tangents
correspond to the angles pi/2 and -pi/2, and it is therefore useful to
pretend that they are valid.

The purpose of atan2() is to handle these special cases, by converting a
naive atan()'s argument into an ordered pair, thus allowing the would-be
inverse tangent of A/0 to be computed without having to divide by 0.  A
simple scene file shows that the *only* time atan2() fails with a domain
error is when *both* A and B are zero.  Of course, (0, 0) is an
indeterminate case, for which returning a value would be nonsensical.

----------[BEGIN CODE]----------
#version 3.7;
global_settings { assumed_gamma 1 }
#declare Args = array [9]
{ <0, 1>, <1, 1>, <1, 0>, <1, -1>, <0, -1>,
  <-1, -1>, <-1, 0>, <-1, 1>, <0, 0>,
}
#for (I, 0, 8)
  #debug concat ("atan2 (", vstr (2, Args[I], ", ", 0, 0), ") = ")
  #debug concat (str (atan2 (Args[I].x, Args[I].y), 0, 6), "\n")
#end
-----------[END CODE]-----------

This scene runs fine with the 3rd and 7th arguments; it does not halt
with a parse error until it gets to the last argument.

Perhaps "unless both A and B are zero" could be added to the documentation.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.