# Vector Math

## Recommended Posts

[ 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
*----*   |
|


##### Share on other sites
x=mag*cos(dir)
y=mag*sin(dir)

Add these up for each one, you get the location of R.

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978709

• 21
• 14
• 12
• 10
• 12