Atan2 in code but not documented nor exposed? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Raccoon
Posts: 49
Joined: 26 Jul 2014, 16:15

Atan2 in code but not documented nor exposed?

01 Mar 2019, 08:57

I notice that the function ATAN2() does not appear in documentation, but it's declared in code. Is there a particular reason this function is missing, or am I misunderstanding the source?

https://github.com/Lexikos/AutoHotkey_L/blob/master/source/qmath.h#L568
Helgef
Posts: 4031
Joined: 17 Jul 2016, 01:02
Contact:

Re: Atan2 in code but not documented nor exposed?

01 Mar 2019, 09:28

You misunderstand. there's probably a thousand functions in the source, I don't think you'd expect them to be available in script.

Cheers.
User avatar
Raccoon
Posts: 49
Joined: 26 Jul 2014, 16:15

Re: Atan2 in code but not documented nor exposed?

01 Mar 2019, 10:19

Here's a slow version for anyone who needs it.

Code: Select all

atan2(y,x) { ; y then x
  if (x > 0)
    return atan(y/x)
  if (x < 0) ; && (y <> 0)
    return atan(y/x) + 3.1415926535898 * ((y >= 0) ? 1.0 : -1.0)
  if (y <> 0) ; && (x = 0)
    return 1.5707963267949 * ((y >= 0) ? 1.0 : -1.0)
  return 0.0
} ; by Raccoon 2019
joefiesta
Posts: 314
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Atan2 in code but not documented nor exposed?

01 Mar 2019, 11:46

what would ATAN2 be? or what is ATAN2() ?
gregster
Posts: 3379
Joined: 30 Sep 2013, 06:48

Re: Atan2 in code but not documented nor exposed?

01 Mar 2019, 11:52

joefiesta wrote:
01 Mar 2019, 11:46
what would ATAN2 be? or what is ATAN2() ?
https://en.wikipedia.org/wiki/Atan2

I thought you were an IBM and Fortran guy... :think:
(Ok, there were other use cases for these, too ;) )
awel20
Posts: 182
Joined: 19 Mar 2018, 14:09

Re: Atan2 in code but not documented nor exposed?

01 Mar 2019, 12:02

Code: Select all

atan2(y, x) {
   return dllcall("msvcrt\atan2", "Double", y, "Double", x, "CDECL Double")
}
joefiesta
Posts: 314
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Atan2 in code but not documented nor exposed?

01 Mar 2019, 12:06

Thanks guys. I did write fortran. In 1967! But, that was just in high school. I never know what quadrant I'm in.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Atan2 in code but not documented nor exposed?

01 Mar 2019, 13:11

- I suggested that it be made a function, here was an attempt at some C++ code.
C++: AHK source code: potential functions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=23&t=54392
- In general, there are various ideas that could very easily be added as built-in functions, e.g. re. maths and dates, because the libraries or custom code is already present in the AHK source code. So it's a case of people noticing the existing code and proposing the new functions.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Rohwedder
Posts: 2340
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Atan2 in code but not documented nor exposed?  Topic is solved

02 Mar 2019, 07:09

Hallo,
or:

Code: Select all

atan2(y,x) {
	Return atan(y/x)+4*atan((x<0)*((y>0)-(y<0)))
}
Edit, this also works on the axes:

Code: Select all

atan2(y,x) {
    Return atan(y/x)+2*(1+(x<0))*atan((x<=0)*((y>=0)-(y<0)))
}
Last edited by Rohwedder on 04 Mar 2019, 06:58, edited 1 time in total.
User avatar
Raccoon
Posts: 49
Joined: 26 Jul 2014, 16:15

Re: Atan2 in code but not documented nor exposed?

02 Mar 2019, 21:00

Very nice, Rohwedder. Quite clever! :D

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 216 guests