开发者

Easy Trig - Move an object in a position

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.


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


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜