Jump to content
Sign in to follow this  
Dielos

Sort Array per Distance

Recommended Posts

How can I sort an array with markers according to their distance to a specific position? I couldn't find any function for it...

Thanks

Share this post


Link to post
Share on other sites

Probably not the most elegant solution, should work fine though.

_unsorted = [<your markers>];
_sorted = [];
_pos = <your position>;

{
    _closest = _unsorted select 0;
    {if ((markerPos _x distance _pos) < (markerPos _closest distance _pos)) then {_closest = _x}} forEach _unsorted;
    _sorted = _sorted + [_closest];
    _unsorted = _unsorted - [_closest]
} forEach _unsorted;

_sorted

Share this post


Link to post
Share on other sites

Thanks a lot, Jezuro!

Simpler than I thought!!!

Share this post


Link to post
Share on other sites

Whoa, I've been wondering about this for sometime.

Thank you Jezuro! It's nice to see you around here.

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  

×