开发者

Calculating X Y movement based on rotation angle?

开发者 https://www.devze.com 2023-02-15 06:45 出处:网络
Say I have an object in 2D space that can rotate and then should move according to its rotation angle.

Say I have an object in 2D space that can rotate and then should move according to its rotation angle.

For example:

  • If angle is 0(pointing upwards), then on_timer it should move 1 by Y and 0 by X.

  • If angle is 45, then it should move 1 by Y and 1 by X.

  • If pointing 90 degrees, then 0 by Y and 1 by X.

  • If pointing 135 degrees, then -1 by Y and +1 by X, 开发者_开发百科etc.

Do you know any functions for calculating this?


well, it seems to move at different speeds for different angles.

For 0 degress (straight up) it moved by 1, but 45 begrees it moved sqrt(1^2 + 1^2) = 1.41.

I think you want to look at Sin and Cos.

X += Speed * Math.Cos(angle);
Y += Speed * Math.Sin(angle);

Regards Gert-Jan


Check this out: http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.matrix.aspx (examples at the bottom of the page)

0

精彩评论

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