Question

I'm trying to move multiple sprites (images) in an elliptical path such that distance (arc distance) remains uniform.

I have tried

  • Move each sprite angle by angle, however the problem with this is that distance moved while moving unit angle around major axis is different than that while moving unit angle around minor axis - hence different distance moved.

  • Move sprites with just changing x-axis uniformly, however it again moves more around major axis.

So any ideas how to move sprites uniformly without them catching-up/overlapping each other?

Other info:

  • it will be called in onMouseMove/onTouchMoved so i guess it shouldn't be much CPU intensive.
  • Although its a general algorithm question but if it helps I'm using cocos2d-x
Was it helpful?

Solution

So this is what i ended up doing (which solved it for me):

I moved it in equation of circle and increased angle by 1 degree. Calculated x and y using sin/cos(angle) * radius. And to make it into an ellipse I multiplied it by a factor.

Factor was yIntercept/xIntercept.

so it looked like this in end

FACTOR = Y_INTERCEPT / X_INTERCEPT;

//calculate previous angle
angle = atan((prev_y/FACTOR)/prev_x);

//increase angle by 1 degree (make sure its not radians in your case)
angle++;

//new x and y
x =  cos(newangle) * X_INTERCEPT;
y =  sin(newangle) * X_INTERCEPT * FACTOR;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top