---
name: "distanceSqr"
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/distanceSqr
revid: 352357
updated: 2024-02-08T14:07:32Z
---

# distanceSqr

*Command · Math - Geometry · Arma 3 v0.50*

## Description

Computes the [squared distance](https://en.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance) between two objects or positions.
This command is faster than [distance](../commands/distance.md) by saving a [square root](../commands/sqrt.md) operation, useful for mass-checking distance without the need of the distance value itself.

## Syntax

### Syntax 1

```sqf
var1 distanceSqr var2
```

**Parameters:**

- `var1`: [Object](../topics/Object.md) or [Position](../topics/Position.md)
- `var2`: [Object](../topics/Object.md) or [Position](../topics/Position.md)

**Returns:** [Number](../topics/Number.md) - distance in meters or 1e10 if distance cannot be calculated

### Syntax 2

*since arma3 2.18*

```sqf
a distanceSqr b
```

**Parameters:**

- `a`: [Number](../topics/Number.md)
- `b`: [Number](../topics/Number.md)

**Returns:** [Number](../topics/Number.md) - distance c calculated as `c = a * a + b * b`

## Examples

### Example 1

```sqf
private _distanceSquared = 5 * 5;
if (player distanceSqr leader player < _distanceSquared) then // similar to player distance leader player < 5
{
    hint "You are less than 5m from the leader!";
};
```

### Example 2

```sqf
private _distance = sqrt ((x2 - x1) ^ 2 + (y2 - y1) ^ 2 + (z2 - z1) ^ 2);
private _distanceSqr = (x2 - x1) ^ 2 + (y2 - y1) ^ 2 + (z2 - z1) ^ 2;
_distance = [x1, y1, z1] distance [x2, y2, z2];
_distanceSqr = [x1, y1, z1] distanceSqr [x2, y2, z2];
_distance = sqrt ([x1, y1, z1] distanceSqr [x2, y2, z2]);
_distanceSqr = ([x1, y1, z1] distance [x2, y2, z2]) ^ 2;
```

## See also

[distance](../commands/distance.md) · [vectorDistanceSqr](../commands/vectorDistanceSqr.md) · [distance2D](../commands/distance2D.md)

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