ArcTan(x,y)?
|
04-06-2017, 03:30 PM
Post: #21
|
|||
|
|||
RE: ArcTan(x,y)?
(04-05-2017 10:41 PM)KeithB Wrote: So if the limit of atan2(x,x) as x approaches 0 is 45, maybe that is what atan2() should return? Clearly, discontinuities near 0 cannot be avoided - I have even seen it suggested online that one could scale values and use integer arithmetic to work around. I am beginning to wonder whether returning an error might be useful. But many Atan2 implementations do return 0, so changing to return 45 instead would introduce compatibility issues. Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
04-06-2017, 03:53 PM
(This post was last modified: 04-06-2017 04:01 PM by Han.)
Post: #22
|
|||
|
|||
RE: ArcTan(x,y)?
(04-06-2017 03:30 PM)StephenG1CMZ Wrote:(04-05-2017 10:41 PM)KeithB Wrote: So if the limit of atan2(x,x) as x approaches 0 is 45, maybe that is what atan2() should return? Care should be taken when evaluating limits of 2-variable functions. See second-to-last post in: http://www.hpmuseum.org/forum/thread-7346.html atan(x/x) is 45, but atan(0/x) is 0 and atan(y/0) is 90*sign(y) (EDIT: I erroneously wrote "infinite" earlier). The limit does not exist so mathematically atan(0/0) is undefined. Graph 3D | QPI | SolveSys |
|||
04-09-2017, 09:50 AM
Post: #23
|
|||
|
|||
RE: ArcTan(x,y)?
(04-06-2017 03:30 PM)StephenG1CMZ Wrote:(04-05-2017 10:41 PM)KeithB Wrote: So if the limit of atan2(x,x) as x approaches 0 is 45, maybe that is what atan2() should return? The PRIME function polar_coordinates, also works in a similar way: polar_coordinates(1,1) returns: [1.41421356237 45] polar_coordinates(0.001,0.001) returns: [1.41421356237ᴇ−3 45] polar_coordinates(0,0) returns: [0 0] |
|||
04-09-2017, 03:47 PM
(This post was last modified: 04-09-2017 05:26 PM by StephenG1CMZ.)
Post: #24
|
|||
|
|||
RE: ArcTan(x,y)?
(04-09-2017 09:50 AM)JMB Wrote:(04-06-2017 03:30 PM)StephenG1CMZ Wrote: Clearly, discontinuities near 0 cannot be avoided - I have even seen it suggested online that one could scale values and use integer arithmetic to work around. I am beginning to wonder whether returning an error might be useful. But many Atan2 implementations do return 0, so changing to return 45 instead would introduce compatibility issues. Interesting. Arctan returns an angle. It was only after Debugging why polar_coordinates sometimes doesnt return at all that I realised polar_coordinates returns a pair of values instead (I know, the plural "coordinates" should have been a clue) - which explains why something goes wrong if you assign it to a global rather than local variable... Code:
I was trying to time which of the three alternatives was slower, and I'm still waiting for polar_coordinates to finish the race [Android version] Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
04-09-2017, 08:00 PM
Post: #25
|
|||
|
|||
RE: ArcTan(x,y)?
(04-09-2017 03:47 PM)StephenG1CMZ Wrote: I was trying to time which of the three alternatives was slower, and I'm still waiting for polar_coordinates to finish the race [Android version] The function polar_coordinates returns a vector, so instead of A you have to use one of the global variables M0, M1, ..., M9 as storage. |
|||
04-09-2017, 09:54 PM
(This post was last modified: 04-09-2017 09:58 PM by StephenG1CMZ.)
Post: #26
|
|||
|
|||
RE: ArcTan(x,y)?
I have put together a little program to illustrate the relative timings of the various methods.
Some of the timings can be improved, but it gives an idea. The printouts seem to be in duration order, quickest first, although sometimes that can change on the Android (presumably because the phone is taking cycles). Code:
Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)