Canvas move object in circle

10,293

The parametric equation for moving in a circle is this:

x=r*cos(theta)
y=r*sin(theta)

theta is the angle, and r the radius.

If you want to know the change in theta to get the desired speed, solving for the distance d you get that the change in theta is: arccos(1-(d/r)^2/2)

The JavaScript functions are Math.cos, Math.sin, and Math.acos, respsectively. They all deal with radians.

Share:
10,293

Related videos on Youtube

Steve P
Author by

Steve P

Updated on October 24, 2022

Comments

  • Steve P
    Steve P over 1 year

    I have a rectangle in canvas, and I know how to move it up and sideways. What I want to do is have it move in a circular motion.

    So my objects(rectangle) x and y would go in a circle.

    Now I am assuming I need a radius for how far out and some formula for the speed(1pixel) to get it rotate on the axis.

    Any idea's?

  • Steve P
    Steve P almost 11 years
    Could you or someone provide me with a jsFiddle on how to add the math libs or how they are connected?
  • simonzack
    simonzack almost 11 years
    Here's a fiddle with fixes of markE's fiddle to make it work, and to show the calculation of the angle: jsfiddle.net/Cu6Zv/1