欢迎各位童鞋转载,转载请注明出处:http://blog.csdn.net/song_hui_xiang
作者新浪微博:http://weibo.com/u/3168848533
作者腾讯微博:http://t.qq.com/song_huixiang
The math library is documented in section 5.6 of the Reference Manual.[1] Below is a summary of the functions and variables provided. Each is described, with an example, on this page.
-
math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.cosh math.deg math.exp math.floor math.fmod math.frexp math.huge math.ldexp math.log math.log10 math.max math.min math.modf math.pi math.pow math.rad math.random math.randomseed math.sin math.sinh math.sqrt math.tanh math.tan
math.abs
Return the absolute, or non-negative value, of a given value.-
> = math.abs(-100) 100 > = math.abs(25.67) 25.67 > = math.abs(0) 0
math.acos , math.asin
Return the inverse cosine and sine of the given value.-
> = math.acos(1) 0 > = math.acos(0) 1.5707963267949 > = math.asin(0) 0 > = math.asin(1) 1.5707963267949
math.atan , math.atan2
Return the inverse tangent. We can do this by supplying y/x ourselves usingmath.atan
or we can pass y and x to
math.atan2
to do this for us.
-
> c, s = math.cos(0.8), math.sin(0.8) > = math.atan(s/c) 0.8 > = math.atan2(s,c) 0.8
math.atan2
should usually be preferred, particularly when converting rectangular co-ordinates to polar co-ordinates. math.atan2
uses 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 cl