Jump to content
beno_83au

Highest Position Between Two Points

Recommended Posts

Good evening. I've been trying to come up with a way to select the highest terrain position along a line (or within a thinly defined area to be precise) and have managed to come up with a fairly rough way to go about it:

private _hpStart = getMarkerPos "hpStart";
private _hpEnd = getMarkerPos "hpEnd";
HighestPoint = [0,0,0];

for "_i" from 1 to 10 do {
	_highestPos = [
		[[_hpStart getPos [(_hpStart distance _hpEnd)/2,_hpStart getDir _hpEnd],[50,(_hpStart distance _hpEnd)/2,_hpStart getDir _hpEnd,true]]],
		[],
		{
			if (((AGLtoASL _this) select 2) > (HighestPoint select 2)) then {
				HighestPoint = AGLtoASL _this;
			};
			((AGLtoASL _this) select 2) > (HighestPoint select 2)
		}
	] call BIS_fnc_randomPos;
};

systemChat format["Highest position found at: %1",HighestPoint];

_markerstr = createMarker [format["m%1",time],HighestPoint];
_markerstr setMarkerShape "ICON";
_markerstr setMarkerType "hd_dot";
_markerstr setMarkerColor "ColorGreen";
_markerstr setMarkerText "Highest position";

The two markers, "hpStart" and "hpEnd" are editor placed, and seeing as BIS_fnc_randomPos only runs 100 times I bumped that amount up to 1000 to see if I got any incorrect results, which I didn't (even after running it A LOT MORE times).

 

Is there a better way to do this that I have not found?

  • Like 1

Share this post


Link to post
Share on other sites

Here's how I'd do it. I would prefer this method since it doesn't rely random sampling. Is it better? I'll leave that up to you to decide. :)

 

Should return a circle (center, radius) with the highest point inside it. The smaller the resolution, the more accurate the result should be.

fn_avgHASL = {
	params [
		"_p",
		["_r", 25],
		["_a", 8]
	];

	_a = (floor _a) max 2;

	private _dDir = 360/_a;
	private _meanZ = getTerrainHeightASL _p;
	for "_i" from 0 to _a-1 do {
		_meanZ = _meanZ + getTerrainHeightASL (_p getPos [_r, _i*_dDir]);
	};

	_meanZ = _meanZ / (_a + 1);
		
	_meanZ
};

fn_highestPointAlongTrack = {
	params ["_pos1", "_pos2", "_width", ["_res", 10]];

	private _dist = _pos1 distance2D _pos2;
	private _dir = _pos1 getDir _pos2;
	private _n = _dist/_res;
	private _highest = _pos1;
	private _h = [_pos1, _width] call fn_avgHASL;
	private ["_p", "_pH"];
	for "_i" from 1 to _n do {
		_p = _pos1 getPos [_res*_i, _dir];
		_pH = [_pos1, _width] call fn_avgHASL;
	};

	[_highest, _res]
};

[markerPos "m1", markerPos "m2", 10, 10] call fn_highestPointAlongTrack;
  • Like 3

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

×