Jump to content

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

## Recommended Posts

If so how?

#### Share this post

##### Share on other sites
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

• 5

#### Share this 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

example use:

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

• 3
• 1

## Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

×

• Clubs