math/atan2

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Also menu state)
(wikipedia link, whole rewrite)
 
Line 1: Line 1:
 
{{Func
 
{{Func
|Description=Returns math.atan(y / x) in radians. The result is between -math.pi and math.pi.
+
|Description=[[wikipedia:atan2|atan2]] functions like {{LibraryFunction|math|atan}}(y / x), except it also takes into account the quadrant of the angle and so doesn't have a limited range of output.
 +
 
 +
{{Note|The Y argument comes first!}}
 
|Realm=Shared and Menu
 
|Realm=Shared and Menu
 
|IsClass=No
 
|IsClass=No
|Name=atan2
 
|Parent=math
 
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 18: Line 18:
 
{{Ret
 
{{Ret
 
|type=number
 
|type=number
|desc=atan2
+
|desc=The angle of the line from (0, 0) to (x, y) in radians, in the range -pi to pi.
 
}}
 
}}
 
{{Example
 
{{Example

Latest revision as of 16:16, 3 August 2018

 math.atan2( )

Contents

Description

atan2 functions like math.atan(y / x), except it also takes into account the quadrant of the angle and so doesn't have a limited range of output.

NOTE

The Y argument comes first!

Arguments

number y

Y coordinate.

Arguments

number x

X coordinate.

Returns

number

The angle of the line from (0, 0) to (x, y) in radians, in the range -pi to pi.

Examples

Example

atan( 1 ) and atan2( 1, 1 ) are both math.pi / 4

atan2( -1, -1 ) equals to ( (-3) * math.pi ) / 4

print( atan( 1 ) )
print( ata2( 1, 1 ) )
print( atan2( -1, -1 ) )

Output:

0.7853981633974483

0.7853981633974483

-2.356194490192345
Personal tools
Navigation