distanceSqr
Jump to navigation
Jump to search
Description
- Description:
- Computes the squared distance between two objects or positions. This command is faster than distance by saving a square root operation, useful for mass-checking distance without the need of the distance value itself.
- Groups:
- Math - Geometry
Syntax
- Syntax:
- var1 distanceSqr var2
- Parameters:
- var1: Object or Position
- var2: Object or Position
- Return Value:
- Number - distance in meters or 1e10 if distance cannot be calculated
Alternative Syntax
- Syntax:
- a distanceSqr b
- Parameters:
- a: Number
- b: Number
- Return Value:
- Number - distance c calculated as c = a * a + b * b
Examples
- Example 1:
- Example 2:
- 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;
Additional Information
- See also:
- distance vectorDistanceSqr distance2D
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note