dimon 28 Posted January 23, 2015 (edited) fnc_getTerrainHeightASL Description: Function to find maximum/minimum heights of the terrain Author: Dimon UA Used scripts: 1.Creating spiral - Author: ArseniyK 2.Sort a numeric array - Author: VVL99 Credits & Thanks: ArseniyK, VVL99 /* File: fnc_getTerrainHeightASL.sqf Author: Dimon UA Used scripts: 1.Creating spiral - Author: ArseniyK 2.Sort a numeric array - Author: VVL99 Credits & Thanks: ArseniyK, VVL99 Description: Function to find maximum/minimum heights of the terrain Parameter(s): _this select 0: position (Array) _this select 1: step (Number) _this select 2: count (Number) _this select 3: true - maximum heights, false minimum heights _this select 4: the size of the returned array (Number) _this select 5: debug (true - otional) Returns: Array - format PositionASL */ private ["_pos","_step","_count","_sort","_size","_debug"]; _pos = _this select 0; _step = _this select 1; _count = _this select 2; _sort = _this select 3; _size = _this select 4; if ((count _this) > 5) then {_debug = _this select 5;}else{_debug =false;}; //=============Creating spiral=============// step = _step; a = -0.3*step; posx = _pos select 0; posy = _pos select 1; x = 1; y = 1; arr = [[posx,posy, getTerrainHeightASL [posx, posy]], [posx+step, posy, getTerrainHeightASL [posx+step, posy]]]; for "_i" from 0 to _count do { r = sqrt (x*x+y*y); tx = a*x+r*y; ty = a*y - r*x; len = sqrt(tx*tx + ty*ty); k = step/len; x = x + tx*k; y = y + ty*k; arr set [_i+1,[x+posx,y+posy,getTerrainHeightASL [x+posx, y+posy]]]; }; if _debug then { { call compile format [" _m%1 = createMarker[""markerRed%1"",[ _x select 0,_x select 1]]; _m%1 setMarkerShape ""ICON""; _m%1 setMarkerType ""DOT""; _m%1 setmarkercolor ""colorred""; ",_forEachIndex]; } foreach arr; }; //==========Sort a numeric array=========// _res_sort = []; { _k = _x; _s = _x select 2; _s_pos = 0; { if _sort then { if (_s < (_x select 2)) then { _s_pos = _s_pos + 1; }; }else{ if (_s > (_x select 2)) then { _s_pos = _s_pos + 1; }; }; } foreach arr; _res_sort set [_s_pos,_k]; } foreach arr; _res_sort resize _size; if _debug then { { call compile format [" _m%1 = createMarker[""markerBlue%1"",[ _x select 0,_x select 1]]; _m%1 setMarkerShape ""ICON""; _m%1 setMarkerType ""DOT""; _m%1 setmarkercolor ""colorblue""; ",_forEachIndex]; } foreach _res_sort; // hint str _res_sort_p; // copyToClipboard str _res_sort_p; }; 1.The highest point http://i59.fastpic.ru/big/2015/0123/59/087e0cfd3b51be77110470ae699e4659.jpg (683 kB) 2.The lowest point http://i64.fastpic.ru/big/2015/0123/0f/2f0fe9f5e262901328f62926d77ae80f.jpg (673 kB) fnc_getTerrainHeightASL Edited January 24, 2015 by Dimon Share this post Link to post Share on other sites
dimon 28 Posted January 26, 2015 fnc_spiral Ðвтор: ArseniyK Creating a spiral grid positions added in one array Parameter(s): _this select 0: position (Array) _this select 1: step (Number) *** *** *** *** (_this select 2) select 0: min radius (Number) *** *** *** *** (_this select 2) select 1: max radius /* File: fnc_spiral.sqf Author: ArseniyK Used scripts: Description: Creating spiral Parameter(s): _this select 0: position (Array) _this select 1: step (Number) (_this select 2) select 0: min radius (Number) _maxrad = (_this select 2) select 1: max radius Returns: Array - format PositionASL */ private ["_pos","_step","_minrad","_maxrad","_posx","_a","_posy","_x","_y","_arr","_debug","_r","_tx","_ty","_len","_k"]; _pos = _this select 0; _step = _this select 1; _minrad = (_this select 2) select 0; _maxrad = (_this select 2) select 1; _debug = false; //=============Creating spiral=============// step = _step; _a = -0.3* step; _posx = _pos select 0; _posy = _pos select 1; _x = _minrad; _y = 1; _arr=[]; for [{_i=0},{true},{_i=_i+1}] do { _r = sqrt (_x*_x+_y*_y); _tx = _a*_x+_r*_y; _ty = _a*_y - _r*_x; _len = sqrt(_tx*_tx + _ty*_ty); _k = step/_len; _x = _x + _tx*_k; _y = _y + _ty*_k; _arr set [_i,[_x+_posx,_y+_posy,getTerrainHeightASL [_x+_posx, _y+_posy]]]; if (((ASLToATL (_arr select _i)) distance _pos) >= _maxrad) exitwith {}; }; if _debug then { { call compile format [" _m%1 = createMarker[""markerRed%1"",[ _x select 0,_x select 1]]; _m%1 setMarkerShape ""ICON""; _m%1 setMarkerType ""DOT""; _m%1 setmarkercolor ""Colorred""; ",_forEachIndex]; } foreach _arr; }; _arr fnc_spiral ============================================ fnc_sortNestedArray2 Used to sort a nested array from lowest to highest or from highest to lowest using quick sort based on the specified column, which must have numerical data. Based: CBA_fnc_sortNestedArray Parameters: *** *** *** *** _array: array - Nested array to be sorted *** *** *** *** _index: integer - sub array item index to be sorted on *** *** *** *** _sort: true - from highest to lowest, false - from lowest to highest /* ---------------------------------------------------------------------------- Function: fnc_sortNestedArray2 Based: CBA_fnc_sortNestedArray Author: Dimon UA Description: Used to sort a nested array from lowest to highest or from highest to lowest using quick sort based on the specified column, which must have numerical data. Parameters: _array: array - Nested array to be sorted _index: integer - sub array item index to be sorted on _sort: true - from highest to lowest, false - from lowest to highest Example: (begin example) _array = [_array,1,_sort] call fnc_sortNestedArray2 (end) Returns: Passed in array Author: Standard algorithm ---------------------------------------------------------------------------- */ /* Modified BIS function to sort nested arrays. Added 2nd parameter to indicate which column (index in nested array) to sort on. Sorts an array of numbers from lowest (left) to highest (right). The passed array is modified by reference. This function uses the quick sort algorithm. */ private ["_re_sort","_debug"]; _re_sort = { private ["_h","_i","_j","_hi","_x","_sort","_id","_lo","_a"]; _a = _this select 0; //array to be sorted _id = _this select 1; _lo = _this select 2;//lower index to sort from _hi = _this select 3;//up _sort = _this select 4;//true - from highest to lowest, false - from lowest to highest _h = nil; //used to make a do-while loop below _i = _lo; _j = _hi; if (count _a == 0) exitWith {}; _x = (_a select ((_lo + _hi) / 2)) select _id; // partition while {isnil "_h" || {_i <= _j}} do { //find first and last elements within bound that are greater / lower than _x if _sort then { while {(_a select _i) select _id > _x} do {_i = (_i) + 1}; while {(_a select _j) select _id < _x} do {_j = (_j) - 1}; }else{ while {(_a select _i) select _id < _x} do {_i = (_i) + 1}; while {(_a select _j) select _id > _x} do {_j = (_j) - 1}; }; if (_i <= _j) then { //swap elements _i and _j _h = _a select _i; _a set [_i, _a select _j]; _a set [_j, _h]; _i = (_i) + 1; _j = (_j) - 1; }; }; // recursion if (_lo < _j) then {[_a, _id, _lo, _j,_sort] call _re_sort}; if (_i < _hi) then {[_a, _id, _i, _hi,_sort] call _re_sort}; }; // and start it off _debug = false; [_this select 0, _this select 1, 0, 0 max ((count (_this select 0))-1), _this select 2] call _re_sort; if _debug then { { call compile format [" _m%1 = createMarker[""markerBrown%1"",[ _x select 0,_x select 1]]; _m%1 setMarkerShape ""ICON""; _m%1 setMarkerType ""DOT""; _m%1 setmarkercolor ""Colorbrown""; ",_forEachIndex]; } foreach (_this select 0); }; // array is already modified by reference, but return the modified array anyway _this select 0 fnc_sortNestedArray2 These two functions allow you to find a position on a particular characteristic of the 3D position [x,y,z]. З.Ы. Sort a numeric array at times slower from fnc_sortNestedArray2 Share this post Link to post Share on other sites