Im drawing a circle on html canvas, the circle is meant to indicate a "ship".
I have the current position (x, y) of the "Ship" object and randomly determine a degree (0 to 360) and an amount value. I then want to alter the ship's current position by the degree and amount.
i.E. ship is currently at 100/100 (on a canvas). I determine degree as 30 and amount as 50.
Now i would like to get the ships new location based on the assumption that 0 degree would indicate "straight up" and 180 degree would indicate straight down while 50 amount indicate a movement of 50 Pixels into the direction determined.
I know it has something to do with Radians, but unfortunally im unable to solve it further.
var ship = {
x: 100,
y: 100
}
var movement = {
degrees: 30,
amount: 50
}
Yes, all angles in JavaScript are in radians. In addition, the canvas context has 0° point to the right so you need to subtract 90° from all angles if you want 0° to be straight up: