Jump to content
Sign in to follow this  
jakkob4682

need help with a math function please :)

Recommended Posts

how do I find the average distance between units that are in an array if possible? i.e.

_cluster = [];
_tgts = _var nearTargets 100;
{
if(_x select 2 == east)then
{
_cluster set [(count _cluster),_x];
};
}forEach _tgts;

I want to calculate the average distance between units that are in _cluster

Share this post


Link to post
Share on other sites

This should give you a working base on how to build an array of distances using BIS_fnc_distance2D. Place a group (player as leader) and a functions module on the editor map and call this with a trigger. It contains screen hints to show you the array being built:

waituntil {!isnil {"bis_fnc_init"}};

_group = units group player;
_distances = [];
_amount = count _group;

// show how many in the group.
hint str _amount;

for [{_count = 0},{_count < _amount},{_count = _count + 1}] do
{
if (_count < (_amount - 1)) then
// get all but "leader to last".
{
	_count1 = _count + 1;
	_obj1 = getpos (_group select _count);
	_obj2 = getpos (_group select _count1);

	// get distance.
	_result = [_obj1,_obj2] call BIS_fnc_distance2D;

// show this distance result.
player sidechat str _result;

	// add distance to the array.
	_distances = _distances + [_result];

// show the compiled array.
player sidechat str _distances;

}
else
// get "leader to last".
{
	_obj1 = getpos (_group select _count);
	_obj2 = getpos (_group select 0);

	// get distance.
	_result = [_obj1,_obj2] call BIS_fnc_distance2D;

// show this distance result.
player sidechat str _result;

	// add distance to the array.
	_distances = _distances + [_result];

// show the compiled array.
player sidechat str _distances;

};
};

From there, add up the values in the array, and divide by the count of values in the array.

EDIT: This example doesn't get distance from each to each, just 1 to 2, 2 to 3, 3 to 4, etc., but should give you the idea.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×