Advertisement

Pendulum

Started by February 05, 2003 12:09 PM
25 comments, last by Keem 22 years ago
Ok, I am modeling the movement of a pendulum ( a point mass on the end of a light rod connected to a smooth axel ). I am fine as far as using the eqn, theta = amplitude * sin ( sqrt(g/l) * time ); this works fine. Where I have problems is how to change the equation to allow the pendulum to "go over the top" i.e. become virtical circular motion, this happens for sufficiently high values of amplitude. I cannot predetermine amplitude as it is linked to user input. Any ideas?
The equation for a simple pendulum is d²y/dt² = -g/l*sin(y). This can not be solved analytically as far as I know but you can do a numerical approximation.
Advertisement
Exactly right, the equation I gave above is obtained by using the approximation sin(x) = x for small values of x. You can also solve it approximately using taylor series which gives y(t) = amplitude * time - (amplitude / 6) * time^3 + ... but this doesn;t seem to give me very nice results on screen.
Right, but you want things to work for big amplitudes, so the approximation sin(x) = x is useless. Therefore, use the differential equation. It covers all cases including when the pendulum goes "over the top".
You might also want to consider using energy relationships in determining the velocities. This might be easier than integrating the forces and accelerations. This way you only need to integrate the velocity to determine where the end will be at the next time step.

Brendan
Brendan"Mathematics is the Queen of the Sciences, and Arithmetic the Queen of Mathematics" -Gauss
AP is correct. The over-the-top pendulum problem is nonlinear, and the x = sin(x) approximation is not valid. A numerical simulation will allow this, and I''ll present that here. Note that I am basically suggesting a very simple numerical approach to integrate the exact equation that AP gave in a prior post. I do sort of derivate the equation and use different notation, but its really the same equation. This is quite simple to do. There is one degree-of-freedom, the angle. And there is a torque that causes the acceleration. The equation of motion is:

Torque = J*rotational_acceleration

Here, Torque is the torque that causes a rotational acceleration about the anchor point of the pendulum. J is the moment of intertia about the anchor point, given by:

J = mass * r2

where r is the length of the tether line (which is assumed to be rigid in this solution).

So J is known. You can calculate torque as follows:

Torque = -mass*g*r*sin(theta)

Note g is the gravitional acceleration constant, so mass*g = weight of the pendulum bob. Theta is the angle of the tether measured counterclockwise from zero straight down.

The tether itself, which is rigid, never exerts a torque on the bob since the force is always directed from the bob through the center of rotation, e.g., there is no lever arm. Only gravity results in a tangential component of force that can cause rotation.

So, with that equation, torque is known at any point. You can solve for rotational_acceleration:

rotational_acceleration = -mass*g*r*sin(theta)/J

Now, rotational_acceleration is the derivative of the angular velocity, which I''ll call theta_dot. (Dot notation refers to time differentiation. In differential equation terms, theta_dot = dtheta/dt). So, we can integrate the equation above to get (using simple Euler integration for simplicity):

theta_dot = theta_dot - delta_time*mass*g*r*sin(theta)/J

So, basically, we''re taking the previous value of theta_dot an incrementing it by the rotational acceleration time the time step, delta_time. Now we have the current angular velocity, which can be integrated to get the current angular location (again using a simple Euler integration for simplicity):

theta = theta + delta_time*theta_dot

Again, we''re taking the current theta and incrementing using the current velocity to get the current position

Now that you know the current position as a theta value, its trivial to get (x,y):

x = r*sin(theta)
y = r*cos(theta)

And that''s your numerical simulation that should handle over-the-top, nonlinear pendulum motion!

Note the units of J are mass*length2
Units of rotational acceleration are 1/time2
(really radians/time2, but radians don''t count in unit analysis)

Thus, units of torque are mass*length2/time2.

And recalling that force = ma, with units of mass*length/time2, we can conclude that the units of torque are also equal to force*length, such as Newton-meters or foot-pounds.

Keep units in mind as you simulate. Its important that everything be consistent!

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Advertisement
I''ll just follow that up and say that simple Euler integration is not actually the best approach for this problem (nor for any other interesting problem), which simulates oscillatory motion. It might work okay, but could very easily be unstable. Adding a little numerical damping can do wonders (make it stable), but it still isn''t the best method to use. The damping would be basically an additional term added to the torque. Calculate it as normal, then:

Torque += coefficient * theta_dot

This extra damping term represents a simple viscous damping model, quite useful in stablizing some numerical integrations. coefficient is the viscous damping coefficient. Experiment to get a good value. Theta_dot is the rotational velocity from the previous time step.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Great, that looks like how i should do it, but what values do I have to change to increase the amplitude mid swing ( the player can change the ammount of swing by "swinging" the joypad )
The behavior is determined by boundary conditions, namely the angle (theta0) and angular velocity (theta_dot0) at some specific time (t0). If you set theta0 to 0, the amplitude is determined solely by theta_dot0.
Is there any way of affecting this after the swing has started?

This topic is closed to new replies.

Advertisement