# Thread: Math formel - determine position relative to approach direction?

1. ## Math formel - determine position relative to approach direction? SOLVED

Requesting a mathematic formula or way to getPos relative to object dir ( 0 - 360 ):

I have a plane with x direction to his wp.

Now i want to spawn a 2nd plane at 1st plane exact same start position and set this wp to the right of the 1 st planes wp based on its direction.

So if 1st plane have direction 0 to wp, i want to place the 2nd planes wp 100m to the right of 1st plane wp, this wich would be exactly +100 in the x plane of the 1st plane wp.

Also if 1st plane has dir 180 i want the 2nd plane wp to be directly to the right of it based on its direction, wich would be -100 in the x plane.

Now these are easy examples and require no formula, but if the dir gets to be 87 or 256 or 12 the issues arise, because the need to use both x and y planes, is it posible to calculate a accurate relative pos from original pos based on approach direction?

Ive looked into the math commands on the wiki but my math skills is insufficient so i dont understand them all, also ive looked into pytagoras but no solution have been reached.

My math skills elude me on this one, i just dont see the answer..
Any help would be greatly appreciated.

2. PHP Code:
``` //Assume you have leader 'plane' and you want to setPos 'wingman'._dist = 150; //Distance from leader plane_offdir = 90; //Relative direction from leader. (90+ here)//Find compass direction to spawn from leader plane_compassDir = ((getDir plane)+_offdir) mod 360;//Find absolute coordinates by adding relative to leader plane_newX = (getPos plane select 0) + (sin _compassDir * _dist);_newY = (getPos plane select 1) + (cos _compassDir * _dist);_newPos = [_newX, _newY, (getPos plane select 2)];//Move wingman plane.wingman setPos _newPos;  ```
Not tested but pretty sure it would work.

Don't forget to give the plane velocity so it don't drop to the ground.

If you want to know the math more in depth then of interest is: "unit circle", "sin" and "cos", in general basic "trigonometry".

3. sweet Thank you, will test this.
Much appreciated.

4. for relative direction you can also use

_relD = [_x,_y] call BIS_fnc_dirTo;

where both _x and _y can be object or position

(The documentation says it returns 0-360, but actually it returns from -180 to 180 so you'll need to if (_relD < 0) then {_relD = 360-_relD} ; )

5. yes i know of the dir function also you can use this code for getting direction from a to b without use of function module:
PHP Code:
``` _vector = ((((posTo select 0) - (posFrom select 0)) atan2 ((posTo select 1) - (posFrom select 1))) + 360) % 360;  ```
And it works flawlessly.

---------- Post added at 01:11 AM ---------- Previous post was at 12:45 AM ----------

PS: Muzzleflash code above works perfect.
Again, thank you.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•