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?
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 .
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 × α .
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θ.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With