Garry's Mod Wiki

Revision Difference

math.atan2#511571

<function name="atan2" parent="math" type="libraryfunc">⤶ <description>⤶ functions like <page>math.atan</page>(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!</note>⤶ </description>⤶ <realm>Shared and Menu</realm>⤶ <args>⤶ <arg name="y" type="number">Y coordinate.</arg>⤶ <arg name="x" type="number">X coordinate.</arg>⤶ </args>⤶ <rets>⤶ <ret name="" type="number">The angle of the line from (0, 0) to (x, y) in radians, in the range -pi to pi.</ret>⤶ </rets>⤶ </function>⤶ ⤶ <example>⤶ <description>⤶ atan( 1 ) and atan2( 1, 1 ) are both math.pi / 4⤶ ⤶ atan2( -1, -1 ) equals to ( (-3) * math.pi ) / 4⤶ </description>⤶ <code>⤶ print( atan( 1 ) )⤶ print( ata2( 1, 1 ) )⤶ print( atan2( -1, -1 ) )⤶ </code>⤶ <output>⤶ 0.7853981633974483⤶ ⤶ 0.7853981633974483⤶ ⤶ -2.356194490192345⤶ </output>⤶ ⤶ </example>