Jump to content
draoth

Is there a way to calculate the midpoint between two or more objects?

Recommended Posts

50 minutes ago, draoth said:

If so how?

 

You mean some kind of center position of multiple positions?

Just handle positions as vectors, add all of them together then divide by the amount of vectors:

 

_array = [position1,position2,position3];//your array holding positions
_getcenterposition = [0,0,0];

{
	_getcenterposition = _x vectorAdd _getcenterposition;

} foreach _array;

_vectorcount = count _array;
_getcenterposition params ["_centerX","_centerY","_centerZ"];
_center = [(_centerX / _vectorcount),(_centerY / _vectorcount),(_centerZ / _vectorcount)];

 

Cheers

  • Like 5

Share this post


Link to post
Share on other sites
15 hours ago, Grumpy Old Man said:

 

You mean some kind of center position of multiple positions?

Just handle positions as vectors, add all of them together then divide by the amount of vectors:

 


_array = [position1,position2,position3];//your array holding positions
_getcenterposition = [0,0,0];

{
	_getcenterposition = _x vectorAdd _getcenterposition;

} foreach _array;

_vectorcount = count _array;
_getcenterposition params ["_centerX","_centerY","_centerZ"];
_center = [(_centerX / _vectorcount),(_centerY / _vectorcount),(_centerZ / _vectorcount)];

 

Cheers

 

Heres a universal method in arma to calculate centroid

 

https://github.com/auQuiksilver/Apex-Framework/blob/master/Apex_framework.terrain/code/functions/fn_geomPolygonCentroid.sqf

 

example use:

 

_positions = [
	[0,0,0],
	[1000,0,0],
	[1000,1000,0],
	[0,1000,0]
];
_centroid = _positions call QS_fnc_geomPolygonCentroid;

 

328lUJ8.jpg

  • Like 3
  • Thanks 1
  • Confused 1

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

×