Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating X Y movement based on rotation angle?

Tags:

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?

like image 274
Rob Avatar asked Mar 04 '11 11:03

Rob


People also ask

How do you find coordinates after a rotation?

Coordinates of Rotation: The point (x,y) rotated an angle of θ counter-clockwise about the origin will land at point (x′,y′) where x′=xcos(θ)−ysin(θ) x ′ = x cos ⁡ ( θ ) − y sin ⁡ and y′=ycos(θ)+xsin(θ) y ′ = y cos ⁡ ( θ ) + x sin ⁡ .

What is the formula for angle rotation?

The angle of rotation between the two points or vertices is the number of central angles times the measure of a single central angle: angle of rotation =m×α = m × α .

How do you find the coordinates when given the angle and distance?

If your starting point is (0,0), and your new point is r units away at an angle of θ, you can find the coordinates of that point using the equations x = r cosθ and y = r sinθ.


1 Answers

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

like image 85
gjvdkamp Avatar answered Nov 09 '22 09:11

gjvdkamp