# Smooth rotation to a desired direction

• 08-22-2012, 05:12 AM
lolmister
Smooth rotation to a desired direction
I have an image with two variables, current direction, and desired direction. I want the Image to smoothly rotate to the desired direction with momentum, but I can't figure out a way to do this myself, andy help would be appreciated.
• 08-22-2012, 05:23 AM
Fubarable
Re: Smooth rotation to a desired direction
Quote:

Originally Posted by lolmister
I have an image with two variables, current direction, and desired direction. I want the Image to smoothly rotate to the desired direction with momentum, but I can't figure out a way to do this myself, andy help would be appreciated.

I can't imagine that we're going to be able to help you much based on this post above as it is way too short on details. Care to show us what you've tried so far? Can you give us a little context? Is this using BufferedImages and Graphics2D, JOGL graphics? Something completely different? Where specifically are you stuck? Come on, please help us out here.
• 08-22-2012, 05:31 AM
lolmister
Re: Smooth rotation to a desired direction
sorry, I am using BufferedImages and Graphics2D. I can rotate the image, I just need help getting the rotation smooth. I have tried to have the Image rotate a certain amount every update towards the goal rotation like this:
Code:

```if(currentrotation>desiredrotation)currentrotation-=1;                 else currentrotation+=1;```
This doesn't compensate for the gap between 0 and 360, and the rotation doesn't have momentum so I am not happy with it.
• 08-22-2012, 05:37 AM
Fubarable
Re: Smooth rotation to a desired direction
You have to expect discrete results when you use ints and degrees. Instead use a double variable and radians in your rotation matrix, and use a rotation step of < 1 degree (equivalent to Math.PI / 180 in radians). I assume that you're using an AffineTransform for your rotation. Play with your code and you'll likely smooth things out.
• 08-22-2012, 05:40 AM
lolmister
Re: Smooth rotation to a desired direction
Ok, thanks for the tips
• 08-22-2012, 09:17 AM
DarrylBurke
Re: Smooth rotation to a desired direction