Sign in to follow this  
LostSource

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this