Author: UGGA_The_Caveman Author Website: Requirements: Version: 1.0 Short description: with this script you can check if a point is in a given angled Rectangle Date: 2014-01-11 17:29 Comments: (0) Rating:

Is Point In angled Rectangle

by
Ugga

Description:
With this script you can check if a point is in a given angled rectangle.

Usage:
Copy and Paste the code to a textfile and rename it "yourDesiredName".sqf
Call the script with these parmeters:
`[_thisPoint ,_areaPoint, _areaLength, _areaRadius, _areaAngle] call compile preprocessFile "Path\yourDesiredName.sqf";`
It will return true if point is in Rectangle or false if not.

• _thisPoint : Point to check
• _areaPoint : Startpoint of the Area (if AreaAngle is pointing left/down it will be adjusted automaticaly)
• _areaLength : Length of the Area (will be adjusted.. areaLength * cos(areaAngle ) )
• _areaRadius : if the distance between _thisPoint and the nearest Point on the middle-Line of the Rectangle is less than _areaRadius, the point is considered as in the Area.
• _areaAngle : Angle of the rectangle (in Arma Angles e.g. 0 means pointing north, 90 is east...)

Script:
```//is given point in given area?
//shape of Area is Pseudo-Rectangle with halfCircles at start and endpoint (radius=_areaRadius)

_thisPoint = _this select 0;
_areaPoint = _this select 1;
_areaLength = _this select 2;
_areaAngle = _this select 4;

//Winkel in Arma sind anders als im  Einheitskreis also müssen wir _areaAngle anpassen
//um 90° im uhrzeiger drehen und dann Spiegeln
//ausserdem sind nur winkel zwischen 0° und 360° zulässig
if ( (_areaAngle <= 90) ) then {_areaAngle = (90 - _areaAngle);};

if ( (_areaAngle > 90) and (_areaAngle <= 180) ) then {_areaAngle = 360 - (_areaAngle - 90);};

if ( (_areaAngle > 180) and (_areaAngle <= 270) ) then {_areaAngle = 270 - (_areaAngle - 180);};

if ( (_areaAngle > 270) ) then {_areaAngle = 180 - (_areaAngle - 270);};
//--

// wenn der punkt zu weit vom startpunkt entfernt ist abbrechen
if ( (_thisPoint distance _areaPoint) > (_areaLength + _areaRadius) ) exitWith {
false
};

//gucken ob der gesuchte x_punkt überhaupt im möglichen x bereich liegt

_temp = ( _areaLength * (cos _areaAngle) );

_x_Start = _areaPoint select 0;
_x_End = _x_Start + _temp;

//tauschen wenn start > end
if (_x_Start > _x_End) then {
_x_Start = _x_End;
_x_End = _areaPoint select 0;
};

if ( ((_thisPoint select 0) < (_x_Start - _areaRadius) ) or ((_thisPoint select 0) > (_x_End + _areaRadius) ) ) exitWith {
false
};
//--

//steigungen der graphen ermitteln
_temp = (cos _areaAngle);

_Text = _Text + format["Sin: %2 Cos: %1 <br />",_temp,(sin _areaAngle)];

_m1 = (sin _areaAngle) / (cos _areaAngle);
_m2 = (1 / _m1) * -1;
//--

//schnittpunkt der 2 graphen ermitteln

//N von F2
_temp = ((_thisPoint select 1)-(_areaPoint select 1)) - (_m2 * ((_thisPoint select 0)-((_areaPoint select 0))));

_sp_x = _temp / ( ( 1 / _m1 ) + _m1 );

_sp_y = _sp_x * _m1;

_sp = [((_areaPoint select 0) + _sp_x),((_areaPoint select 1) + _sp_y),(_thisPoint select 2)];
//--

//entfernung des gesuchten punktes zum schnittpunkt
_temp = (_thisPoint distance _sp);

if (_temp > _areaRadius) exitwith {
false
};
//--

true```

Notes:
Feel free to use/edit this file as you want.
I would be happy about credits.