I'm looking for a way to smoothly increase or decrease the speed of a circular movement.
Using the parametric equation of a circle, I can move an object in a circle over time:
x = center_x + radius * sin(time * speed)
y = center_y + radius * cos(time * speed)
The problem with this approach is that I can't simply do speed = speed + 1
to accelerate the object because it results in jerky movement. This makes sense because the x and y values are being recalculated every frame based on absolute values rather than relative to the object's previous position.
Another approach might be to use a vector that represents the velocity of the object, then apply a circular motion to the vector instead:
v_x = radius * sin(time * speed)
v_y = radius * cos(time * speed)
x = x + v_x
y = y + v_y
The problem with this approach is that if I change the speed then the radius will grow or shrink. This makes sense because the movement is relative to the current position and so time is essentially skipped if I alter the speed.
One implementation I can think of that might work is using a vector that points from the object to the center of the circle. Then I could calculate the tangent of the circle at the object's position by using the perpendicular vector, normalize it and scale it by the speed. I haven't implemented this yet because it seems like overkill for a problem like this, so please let me know if a simpler solution exists. Thanks!