Sign in to follow this  
recon6

Problem with speed

Recommended Posts

Hi. I'm using SDL to create a shape that moves in an anti-clockwise direction which increases it's radius after one revolution. The problem is that after each increase in the radius, the circle moves faster than it did in the previous revolution. How can i get it to move at the same speed all the time? while (gameRunning ) { if (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { gameRunning = false; } SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); xpos2 = (r2*cos(angle2) + centreX); ypos2 = (r2*sin(angle2) + centreY); angle2 -=0.02; if (angle2 <= -4.71) { angle2 = 1.57; ypos2 +=10; r2 +=10; } filledCircleRGBA(screen, xpos2, ypos2, 5, 20, 250, 30, 255); SDL_Flip(screen); } Where r and centreX & Y are globally defined variables.

Share this post


Link to post
Share on other sites
Quote:
Original post by recon6
How can i get it to move at the same speed all the time?

By normalizing your angular velocity.

You have your object cover an angle t at a radius r. When r increases, but t remains constant, you've increased effective angular velocity. To keep it constant:

t2 = t1 * r1/r2

where t1 and r1 are initial and t2 and r2 are final angle and radius, respectively. Or, simply always divide your vector displacements (in x and y) by the radius, as ToohrVyk said.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
You have your object cover an angle t at a radius r. When r increases, but t remains constant, you've increased effective angular velocity.


I may be wrong, but don't you mean "you've increase the linear velocity"? I was under the impression that constant angular velocity means that you rotate the same angle per unit time.

Thus, a 30 degree rotation over 1 unit of time at radius 1 would be a smaller distance traveled than a 30 degree rotation over 1 unit of time at radius 2. The distance traveled over the same time span in the second case is more, but the angle traveled is the same. His angle isn't changing.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this