OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Rommel92 on 02 Jun 2008, 09:01:46
-
Question
Plane Velocity = [20,10,10]
From this velocity how do I get the direction of the plane?
Plane Coordinates: [0,0,0] -- Plane Coordinates 2: [10,20,20]
From this pair of coordinates how do I get the direction of the plane. (Mathematically)
Direction : 95 degrees || Unit coordinates [0,0,0]
From this information how do I make the unit move 10m on a bearing of 95 degrees.
:lol:
Even if its not direct answers, any help is appreciated.
-
_dir = (_velocity select 0) atan2 (_velocity select 1)
-
_dir = (_velocity select 0) atan2 (_velocity select 1)
so Q2 would be:
[0,0,0] - [10,20,20] = [-10,-20,-20]
(X atan2 Z) = 15.2084
But how about question three? :confused:
-
_dir = 95;
_spd = 20; // m/s
_posini = getPos _veh;
while{(_posini distance _veh) < _max_distance} do
{
_veh setDir _dir;
_veh setVelocity [sin(_dir)*_spd, cos(_dir)*_spd, 0];
Sleep 0.002;
};
-
Solved!
Mando, I don't think you understood my question. :no:
Why is it: atan2 = 63.435 degrees, yet: tan(20/10) = -2.18... which would be the regular trigonometric way. (tan (angle) = opposite / adjacent.)... something to do with Vector?
Also a really weird discovery here, if you could shed some light I'd be very thankful.
(http://img233.imageshack.us/img233/9391/83499971ch8.jpg)
ArmA Values were determined by:
nil = player spawn {_pos = getPos player; waitUntil {player distance _pos > 10}; hint format ["%1",[((getpos player select 0) - (_pos select 0)),((getpos player select 1) - (_pos select 1)),((getpos player select 2) - (_pos select 2))]]}
Moving on a 45 degree bearing through the compass.
So why the degree divided by 3.3.
(http://img80.imageshack.us/img80/7051/trigiz5.jpg)
:dunno:
EDIT: FYI, I came to this conclusion on multiple evidence, it was discovered via a 10 degree angle not equalling the math, I then noticed a pattern in the values, and noticed 33 degrees produced the values for 10, I then tried this for 45, then divided by 3 (rounded) and got the above values (close, but the rounded is obvious in the results).
I have since tried this for many different angles, with similiar results. :blink:
-
you canno use atan because atan cannot resolve the quadrant. you need to use atan2:
((destination_pos select 0)-(origin_pos select 0)) atan2 ((destination_pos select 0)-(origin_pos select 0))
This will give you a value from 0 to 180 and from 0 to -180.
But if you already have the direction you are looking for, as in your original question, then calculation the velocity vector is just a matter of [sin(_ang)*speed, cos(_ang)*speed, 0]
-
Any idea about the third question, which is the most pro-dominant at this stage. :P
-
:blink:
the third question was already answered few posts above:
This will move a plane, for example, 100m heading 95 degs at a speed of 20 m/s
_dir = 95;
_spd = 20; // m/s
_posini = getPos _veh;
_max_distance = 100;
while{(_posini distance _veh) < _max_distance} do
{
_veh setDir _dir;
_veh setVelocity [sin(_dir)*_spd, cos(_dir)*_spd, 0];
Sleep 0.002;
};
Is that the third question?
-
I'll rephrase the question. I want the coordinates of a unit (Mathematically, not through the game) on a bearing 95 degrees and 10m from its original position. Which is where from which I found the answer through trig, I could not solve because of ArmAs extremely strange results.
-
_coords = [(getPos _unit select 0)+sin(95)*10,(getPos _unit select 1)+cos(95)*10, getPos _unit select 2];
Note that these will be AGL coords, so the altitude 10m away might be different than original, if you need to keep exact level then use getPosASL instead of getPos, the resulting coords will be ASL, not AGL.
-
Baddo informed me of the error, turns out I had my calculator in radians not degrees.
Thanks for the help. :good: