Public Group

# Problem with speed

This topic is 3932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Quote:
 Original post by recon6How can i get it to move at the same speed all the time?

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 on other sites
Quote:
 Original post by OluseyiYou 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.

Thanks.

Thanks.

1. 1
Rutin
19
2. 2
JoeJ
15
3. 3
4. 4
5. 5

• 24
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631699
• Total Posts
3001776
×