views:

87

answers:

3

I know this is quite easy trigonomety, however I was never introducted to vectors etc, and I'm at a loss understanding how this works.

Given an object at point XY, and a direction N, how do you move that object in that direction?

Also, given am object at point XY, and a destination at point XY, how do you move an object towards the destination?

I understand there is some need for adding vectors etc.

Could somebody please refer me to some easy material to digest?

Thanks.

A: 

A quick Google search will give you just about all the resources you need on Vector Math.

Josh
Thanks, wasn't sure what it was even called!
I have to admit that Linear Algebra was not my favorite topic until I began doing 3D graphics. Then I wished I had payed more attention. I still have my book, and the only chapter I really reference is the first couple on vectors.
Josh
+2  A: 

Given an object at point XY, and a direction N, how do you move that object in that direction?

If your point is (X,Y) and your direction is a vector (NX, NY), you simply add those two. Now your object is at the position (X + NX, Y + NY).

Also, given am object at point XY, and a destination at point XY, how do you move an object towards the destination?

If your source point is (SX, SY) and your destination point is (DX, DY), you usually move the object along (SX + t * (DX - SX), SY + t * (DY - SY)) with t = 0..1

schnaader
A: 

Given a point x,y, an angle n and a distance d, you calculate the new position like this:

x = x + cos(n) * d
y = y + sin(n) * d

Given the point x,y, the destination x2,y2 and the distance to move d, the distance between the points is:

dt = ((x2 - x)^2 + (y2 - y)^2) ^ 0.5

The new position is:

x = x + (x2 - x) * (d / dt)
y = y + (y2 - y) * (d / dt)
Guffa