Results 1 to 5 of 5

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

  1. #1
    Warrant Officer Demonized's Avatar
    Join Date
    Nov 16 2010
    Location
    Back from afk 2013
    Posts
    2,614

    Smile 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.
    Last edited by Demonized; Feb 5 2011 at 02:45. Reason: Solved
    My scripts:
    Spoiler:

    what to do when posting any kind of code dammit!!

    Any new mission editor or scripter in Arma2 should have read Mr Murrays Editing Guide Deluxe at least once, it still applies for A2 even though it was made for Armed Assault.

  2. #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)+_offdirmod 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".
    Last edited by Muzzleflash; Feb 4 2011 at 21:25.

  3. #3
    Warrant Officer Demonized's Avatar
    Join Date
    Nov 16 2010
    Location
    Back from afk 2013
    Posts
    2,614
    Author of the Thread
    sweet Thank you, will test this.
    Much appreciated.

  4. #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} ; )
    Last edited by zapat; Feb 4 2011 at 22:04.

  5. #5
    Warrant Officer Demonized's Avatar
    Join Date
    Nov 16 2010
    Location
    Back from afk 2013
    Posts
    2,614
    Author of the Thread
    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.
    Last edited by Demonized; Feb 5 2011 at 02:58. Reason: added info on fnc module

Posting Permissions

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