If we assume that a planet is traveling in a perfect circle, how could wesimulate this motion? First, let's assume that our circle is centered at coordinates (0,0)left parenthesis, 0, comma, 0, right parenthesis and has a radius, r.
Promień planety r od środka okręgu (0,0)
How can we simulate the motion of a planet orbiting around the perimeter of a circle?
Obieganie planety po obwodzie
Zauważ, że pozycja planety opiera się na odległości od środka (promień r) i kącie dookoła okręgu (0 do 360 stopni). These are known as polar coordinates.
However, in order to draw this planet we need to define the planet's position using x,yx, comma, y coordinates. These are known as cartesian coordinates.
Cartesian coordinates of the planet's position (x,y)
The length of the triangle is xx, the height is yy, the hypotenuse is r and the angle at the origin is the planets current angle around its orbit. Now we just need to find the distance of xx and yy using basic trigonometry:
To animate the motion of a planet we can increment the angle θ by one degree at each frame and the planet will move around the origin in a circle. Your turn!
Next we can try animating our own planet in the upcoming challenge.