{"name":"atan2","operator":null,"title":"atan2","type":"command","url":"https://community.bistudio.com/wiki/atan2","revid":363173,"updated":"2024-03-25T08:38:17Z","groups":["Math - Geometry"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"ArcTangent of *y/x*. Used to determine the angle of a vector *[y,x]*. Result in Degrees between -180 and 180.\n\n> [!NOTE]\n> This command can handle *x* being 0, unlike when using atan, and will return 90\n\n> [!IMPORTANT]\n> This command has higher precedence than the select command, therefore beware of the case below:\n>\n> ```sqf\n>  _pos select 0  atan2 (_pos select 1) // error\n> (_pos select 0) atan2 (_pos select 1) // OK\n> ```\n>\n> Alternatively, consider using the # operator: `_pos # 0 atan2 _pos # 1`","syntaxes":[{"syntax":"y atan2 x","since":null,"effect":null,"exec":null,"params":[{"name":"y","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"y: Number"},{"name":"x","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"x: Number"}],"returns":{"type":"Number","types":["Number"],"description":null,"text":"Number"},"form":"binary","operator":null,"left":{"text":"y","types":["Number"]},"right":{"text":"x","types":["Number"]}}],"examples":[{"text":"```sqf\n_yx = [5,3];\n_degrees = (_yx select 0) atan2 (_yx select 1); // 59.0362\n```","code":["_yx = [5,3];\n_degrees = (_yx select 0) atan2 (_yx select 1); // 59.0362"]},{"text":"Get direction from _obj1 to _obj2:\n\n```sqf\n_vd = getPosASL _obj2 vectorDiff getPosASL _obj1;\n_dir = (_vd select 0) atan2 (_vd select 1); // _dir range from -180 to +180\n_dir = (_dir + 360) % 360; // _dir range from 0 to 360\n```","code":["_vd = getPosASL _obj2 vectorDiff getPosASL _obj1;\n_dir = (_vd select 0) atan2 (_vd select 1); // _dir range from -180 to +180\n_dir = (_dir + 360) % 360; // _dir range from 0 to 360"]},{"text":"Get relative direction from _obj1 to _obj2:\n\n```sqf\n_yx = _obj1 worldToModel getPosASL _obj2;\n_dir = (_yx select 0) atan2 (_yx select 1); // _dir range from -180 to +180\n_dir = (_dir + 360) % 360; // _dir range from 0 to 360\n```","code":["_yx = _obj1 worldToModel getPosASL _obj2;\n_dir = (_yx select 0) atan2 (_yx select 1); // _dir range from -180 to +180\n_dir = (_dir + 360) % 360; // _dir range from 0 to 360"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["atan","tan","sin","cos","asin","acos","rad","pi","vectorCos","BIS_fnc_dirTo","getRelPos","getRelDir"],"notes":[],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Math - Geometry","Introduced with Operation Flashpoint version 1.00","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}