---
name: "atan2"
type: command
status: ok
groups: ["Math - Geometry"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/atan2
revid: 363173
updated: 2024-03-25T08:38:17Z
---

# atan2

*Command · Math - Geometry · Arma 3 v0.50 · introduced in Operation Flashpoint v1.00*

## Description

ArcTangent of *y/x*. Used to determine the angle of a vector *[y,x]*. Result in [Degrees](../topics/Number.md#degrees) between -180 and 180.

> [!NOTE]
> This command can handle *x* being 0, unlike when using [atan](../commands/atan.md), and will return 90

> [!IMPORTANT]
> This command has [higher precedence](../topics/SQF_Syntax.md#rules-of-precedence) than the [select](../commands/select.md) command, therefore beware of the case below:
>
> ```sqf
>  _pos select 0  atan2 (_pos select 1) // error
> (_pos select 0) atan2 (_pos select 1) // OK
> ```
>
> Alternatively, consider using the [#](../commands/a_hash_b.md) operator: `_pos # 0 atan2 _pos # 1`

## Syntax

```sqf
y atan2 x
```

**Parameters:**

- `y`: [Number](../topics/Number.md)
- `x`: [Number](../topics/Number.md)

**Returns:** [Number](../topics/Number.md)

## Examples

### Example 1

```sqf
_yx = [5,3];
_degrees = (_yx select 0) atan2 (_yx select 1); // 59.0362
```

### Example 2

Get direction from _obj1 to _obj2:

```sqf
_vd = getPosASL _obj2 vectorDiff getPosASL _obj1;
_dir = (_vd select 0) atan2 (_vd select 1); // _dir range from -180 to +180
_dir = (_dir + 360) % 360; // _dir range from 0 to 360
```

### Example 3

Get relative direction from _obj1 to _obj2:

```sqf
_yx = _obj1 worldToModel getPosASL _obj2;
_dir = (_yx select 0) atan2 (_yx select 1); // _dir range from -180 to +180
_dir = (_dir + 360) % 360; // _dir range from 0 to 360
```

## See also

[atan](../commands/atan.md) · [tan](../commands/tan.md) · [sin](../commands/sin.md) · [cos](../commands/cos.md) · [asin](../commands/asin.md) · [acos](../commands/acos.md) · [rad](../commands/rad.md) · [pi](../commands/pi.md) · [vectorCos](../commands/vectorCos.md) · [BIS_fnc_dirTo](../functions/BIS_fnc_dirTo.md) · [getRelPos](../commands/getRelPos.md) · [getRelDir](../commands/getRelDir.md)

<sub>Source: [BI Community Wiki — atan2](https://community.bistudio.com/wiki/atan2) (revision 363173).</sub>
