I don't get these return values at all. math.atan(1,0) gives me pi/4 (instead of pi/2) and rotating towards (0,-1) decreases the value towards 0 instead of increasing.http://lua-users.org/wiki/MathLibraryTutorial wrote: Return the inverse tangent in radians. We can do this by supplying y/x ourselves or we can pass y and x to math.atan to do this for us.
[...]
Using two arguments should usually be preferred, particularly when converting rectangular co-ordinates to polar co-ordinates. It will use the sign of both arguments to place the result into the correct quadrant, and also produces correct values when one of its arguments is 0 or very close to 0.Code: Select all
> = math.atan(1, 0), math.atan(-1, 0), math.atan(0, 1), math.atan(0, -1) 1.5707963267949 -1.5707963267949 0 3.1415926535898
I tried:
Code: Select all
local dir = game.tick%360
p.print('test direction('..dir..', '..math.deg(math.atan(math.sin(math.rad(dir)),math.cos(math.rad(dir))))..')')
Code: Select all
p.print('test direction('..dir..', '..math.deg(math.atan(math.sin(math.rad(dir)),1354586313153))..')')
So I tried:
Code: Select all
p.print('test direction('..dir..', '..math.deg(math.atan(math.sin(math.rad(dir))/math.cos(math.rad(dir)),564863154))..')')
So it's just calling math.tan(a) instead of math.tan(a,b)
I can work with that, but it's been such a bother finding out that it doesn't exist and wondering why my code doesn't work.
Found official documentation for math.atan(y,x) also.
Might be worth checking that other functions like math.log (x [, base]) and similar are correct.http://www.lua.org/manual/5.3/manual.html#pdf-math.atan wrote: math.atan (y [, x])
Returns the arc tangent of y/x (in radians), but uses the signs of both parameters to find the quadrant of the result. (It also handles correctly the case of x being zero.)
The default value for x is 1, so that the call math.atan(y) returns the arc tangent of y.