I am not sure if this is useful but:
I was searching for a quick and easy way of generating positions in an arc that could be used for flanking waypoints. I came across this forum post which showed a formula for brezier curves taken from wikipedia:
http://www.coderanch.com/t/480970/Game-Development/java/plot-curve-points
http://en.wikipedia.org/wiki/B%C3%A9zier_curve
I decided to use that code and alter it to ARMA script while making some adjustments to allow for the user to sample only a few points along the curve with the end point being the _end point.
Add this to init.sqf or rename the function as you see fit:
rej_fnc_bezier = compile preProcessFileLineNumbers "rej_fnc_bezier.sqf";
Create a rej_fnc_bezier.sqf or a renamed version as you see fit and add it to the mission folder then add the following code:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//-- This script is a Bezier Curve function and will return a specified number of points along the Bezier Curve --//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private["_vector1","_vector2","_controlVector","_numberOfPoints","_removeStartPos","_x","_y","_increments","_positions"];
_vector1 = _this select 0;
_vector2 = _this select 1;
_controlVector = _this select 2;
_numberOfPoints = _this select 3;
_removeStartPos = _this select 4;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//-- Double distance for the control vector to make the peak of the curve pass through the controlVector --//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
_midPoint_1 = ((_vector1 select 0) + (_vector2 select 0)) / 2;
_midPoint_2 = ((_vector1 select 1) + (_vector2 select 1)) / 2;
_midPoint = [_midPoint_1,_midPoint_2,0];
_midPoint_1 = ((_vector1 select 0) + (_vector2 select 0)) / 2;
_midPoint_2 = ((_midPoint select 1) + (_midPoint select 1)) / 2;
_midPoint = [_midPoint_1,_midPoint_2,0];
_vectorDiff = _controlVector vectorDiff _midPoint;
_controlVector = _controlVector vectorAdd _vectorDiff;
/////////////////////////
//-- Calculate curve --//
/////////////////////////
if (_numberOfPoints >= 1) then
{
_increments = 1 / _numberOfPoints;
_positions = [];
for [{_i = 0.0},{_i <= 1},{_i =_i + _increments}] do {
_x = ((1 - _i) * (1 - _i) * (_vector1 select 0) + 2 * (1 - _i) * _i * (_controlVector select 0) + _i * _i * (_vector2 select 0));
_y =((1 - _i) * (1 - _i) * (_vector1 select 1) + 2 * (1 - _i) * _i * (_controlVector select 1) + _i * _i * (_vector2 select 1));
_positions pushback [_x,_y,0];
_markname = format["%1 %2%3",("testmarker"),(ceil random 999),(ceil random 999),(ceil random 999)]; //-- For demo purpose only. Please remove.
_marker = createMarker [_markname,[_x,_y,0]]; //-- For demo purpose only. Please remove.
_markname setMarkerType "hd_dot"; //-- For demo purpose only. Please remove.
_markname setMarkerColor "ColorBlack"; //-- For demo purpose only. Please remove.
};
if (_removeStartPos) then
{
_positions deleteAt 0;
};
} else {
_positions = _vector2;
};
_positions
Call the function as follows:
_curvePositionsArray = [startPos,endPos,controlPos,4,true] call rej_fnc_bezier;
hint format["POSITIONS RETURNED: %1",(curvePositionsArray)];
-Where _startPos is the starting position,
-Where _endPos is the destination position,
-Where _controlPos is the position where the curve should flex towards. I've coded it so that the peak or the curve near the peak should pass through the controlPos. This is the direction where the curve tip will point towards and hopefully pass through.
-Where 4 can be any number of points you want returned in the array *,
-Where true is whether or not you want the starting point returned in the array (it will always be included in the array regardless of whether you asked for 1 position or more to be returned so use this to delete the starting Position from the array.
* Make sure you use whole numbers. Using anything less that 1 will return the end position and using any non whole numbers like 1.9 will probably not return the end destination. I tested 1.9 and it landed me somewhere in the middle of the curve.
Note: I added a quick marker generation for the points so you can get a visual representation of the points being generated. Feel free to remove.
I only spent a short time testing this script out so let me know if there are any weird problems .