Public Group

# Animation issue

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

## Recommended Posts

I've recently started a small project, but for some strange reason, my animation is failing me. My guess is that something is wrong with the function on how I'm trying to change the angle.

var theta:Number;    var h = 225 * Math.cos(theta);    var k = 225 * Math.sin(theta);    var animation = Timeline {        repeatCount: Timeline.INDEFINITE;        keyFrames: KeyFrame {            time: 1s;            action: function() {                theta = Math.toDegrees(theta - 6);            }        }    }

##### Share on other sites
How is it failing you, what is wrong? What is it supposed to do?

theta = Math.toDegrees(theta - 6);

This looks all kinds of wrong. You have a theta value which I'd assume is in radians, you subtract 6 radians from it (that's a lot!), and then store it back in the same variable as degrees? Make sure this is what you mean to be doing.

##### Share on other sites
I actually want it to decrease by 6 degrees, so that'd be the first place to start. Ideally, the orbiter should rotate 6 degree per second with its center being calculated based on theta.

##### Share on other sites
If theta is in radians, and you'd like to subtract 6 degrees from it, you should first convert degrees to radians so that things are in the same units.

Pi radians = 180 degrees. The conversion factor from degrees to radians is (PI/180), where PI = famous numerical constant. Google it for a precise value to define it as.

So, to change 6 degrees into radians:

deltaDegrees = 6.0;deltaRadians = 6.0 * PI / 180.0; // converts 6 degrees to radianstheta = Math.toDegrees(theta - deltaRadians);

I don't know what you're using but perhaps there is a Math.toRadians(*) function? In any case you should work in degrees or radians, but not both. Furthermore in most languages inputs to trigonometric functions must be expressed as radians.

##### Share on other sites
There is a toRadians, so I guess that's the way I'll have to go. You've given me enough to work with, so I'll see if I can get it working.

##### Share on other sites
Quote:
 Original post by FujiThere is a toRadians, so I guess that's the way I'll have to go. You've given me enough to work with, so I'll see if I can get it working.

What? it's already in radians... why would you convert it again. convert it to degrees and THEN subtract six:

This code:
theta = Math.toDegrees(theta - 6);

Subtracts 6 from theta which is in radians and then converts that value to degrees. Do the subtracting after the toDegrees conversion.

-me

##### Share on other sites
I see. The value I've been initializing with is still in degrees. I'll get that fixed.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 28
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631772
• Total Posts
3002260
×