Home   Help Search Login Register  

Author Topic: Trigonometry  (Read 1421 times)

0 Members and 1 Guest are viewing this topic.

Offline Rommel92

  • Members
  • *
Trigonometry
« on: 02 Jun 2008, 09:01:46 »
Question

Code: [Select]
Plane Velocity = [20,10,10]
From this velocity how do I get the direction of the plane?

Code: [Select]
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)

Code: [Select]
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.
« Last Edit: 02 Jun 2008, 09:15:53 by Rommel92 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Trigonometry
« Reply #1 on: 02 Jun 2008, 09:20:20 »
Code: [Select]
_dir = (_velocity select 0) atan2 (_velocity select 1)

Offline Rommel92

  • Members
  • *
Re: Trigonometry
« Reply #2 on: 02 Jun 2008, 09:38:52 »
Code: [Select]
_dir = (_velocity select 0) atan2 (_velocity select 1)
so Q2 would be:
Code: [Select]
[0,0,0] - [10,20,20] = [-10,-20,-20] 
(X atan2 Z) = 15.2084

But how about question three?  :confused:
« Last Edit: 02 Jun 2008, 09:42:25 by Rommel92 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Trigonometry
« Reply #3 on: 02 Jun 2008, 09:56:09 »
Code: [Select]
_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;
};

Offline Rommel92

  • Members
  • *
Re: Trigonometry
« Reply #4 on: 02 Jun 2008, 11:07:42 »
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.


ArmA Values were determined by:
Code: [Select]
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.


 :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:
« Last Edit: 02 Jun 2008, 21:44:39 by Rommel92 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Trigonometry
« Reply #5 on: 02 Jun 2008, 22:52:22 »
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]

Offline Rommel92

  • Members
  • *
Re: Trigonometry
« Reply #6 on: 02 Jun 2008, 22:54:51 »
Any idea about the third question, which is the most pro-dominant at this stage.  :P

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Trigonometry
« Reply #7 on: 02 Jun 2008, 23:36:26 »
 :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
Code: [Select]
_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?

Offline Rommel92

  • Members
  • *
Re: Trigonometry
« Reply #8 on: 03 Jun 2008, 00:01:16 »
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.


Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Trigonometry
« Reply #9 on: 03 Jun 2008, 00:06:53 »
Code: [Select]
_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.

Offline Rommel92

  • Members
  • *
Re: Trigonometry
« Reply #10 on: 03 Jun 2008, 08:31:46 »
Baddo informed me of the error, turns out I had my calculator in radians not degrees.

Thanks for the help.  :good:
« Last Edit: 22 Jun 2013, 06:04:56 by Rommel92 »