Vector Math

Started by
5 comments, last by grhodes_at_work 18 years, 1 month ago
[ Vector Addition ] Say I have three vectors A, B, C with the mag. and dir. discribed below:

vector |  mag   | dir (degrees)
---------------------------------
  A    |  5 cm  |  90
       |        |
  B    |  3 cm  |  210
       |        |
  C    |  4 cm  |  180
I'm wanting to add the three vectors A + B + C = R. How would I do this, it's confusing me some what (well actually alot). Because I know R != 12. * = vector head

          * 
         /|
      B / |
   C   /  | A
 *----*   |
          |
Advertisement
x=mag*cos(dir)
y=mag*sin(dir)

Add these up for each one, you get the location of R.
Yea I saw that on goggle, but what I'm wanting is not the position (location) of R in a plain, but just its length.
Well, if you have the starting location and the end location you can use a simple "distance between two points" equation to figure length:

I believe it's L = (x2-x1)/(y2-y1)

Someone correct me if that's wrong. Hope it helps.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Euclidean distance, and length of a vector.
To find a vector from coordinates is easy. When you add the vectors using y=a*sin(dir) and x=a*cos(dir), you get a resultant x and y:
length=square_root(x^2+y^2);dir=tan(y/x);


Annother way of doing this is writing a function that adds two vectors and returns the resultant. To add the three vectors, you could then do:
vector R=add(add(A,B),C);

To add two vectors, you can use the law of cosines and the law of sines.
"Are you threatening me, Master Jedi?" - Chancellor Palpatine
Folks, this question is presented in a way that strongly resembles a school or homework problem. Try to recognize this kind of clean, very theoretical problem statement, and in the future provide only advice or link to resources. Gamedev is not a homework site.

Read the Forum FAQ for more details, along with links to pages that are appropriate for school type problems.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement