distanceSqr: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) No edit summary |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
Line 7: | Line 7: | ||
|descr= Computes the {{Link|https://en.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance|squared distance}} between two objects or positions. | |descr= Computes the {{Link|https://en.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance|squared distance}} between two objects or positions. | ||
This command is faster than {{Link|distance}} by saving a {{Link|sqrt|square root}} operation, useful for mass-checking distance without the need of the distance value itself. | |||
|s1= var1 [[distanceSqr]] var2 | |s1= var1 [[distanceSqr]] var2 | ||
Line 14: | Line 15: | ||
|p2= var2: [[Object]] or [[Position]] | |p2= var2: [[Object]] or [[Position]] | ||
|r1= [[Number]] | |r1= [[Number]] - distance in meters or 1e10 if distance cannot be calculated | ||
| | |s2= a [[distanceSqr]] b | ||
|s2since= arma3 2.16 | |s2since= arma3 2.16 | ||
|p21= a: [[Number]] | |p21= a: [[Number]] | ||
|p22= b: [[Number]] | |||
|p22= b: [[Number]] | |||
|r2= [[Number]] - distance c calculated as c = a * a + b * b | |r2= [[Number]] - distance c calculated as <sqf inline>c = a * a + b * b</sqf> | ||
|x1= <sqf>player distanceSqr | |x1= <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!"; | |||
}; | |||
</sqf> | |||
|x2= <sqf>_distance = sqrt ((x2 - x1) ^ 2 + (y2 - y1) ^ 2 + (z2 - z1) ^ 2); | |x2= <sqf> | ||
_distanceSqr = (x2 - x1) ^ 2 + (y2 - y1) ^ 2 + (z2 - z1) ^ 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]; | _distance = [x1, y1, z1] distance [x2, y2, z2]; | ||
_distanceSqr = [x1, y1, z1] distanceSqr [x2, y2, z2]; | _distanceSqr = [x1, y1, z1] distanceSqr [x2, y2, z2]; | ||
_distance = sqrt ([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;</sqf> | _distanceSqr = ([x1, y1, z1] distance [x2, y2, z2]) ^ 2; | ||
</sqf> | |||
<!-- KK, your turn! | <!-- KK, your turn! |
Revision as of 10:20, 2 November 2023
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