-1

I need to make a C# simulator for a simple pendulum. I have been searching the web for 3 days and I am stuck.

The problem is I have found many equations that would give the angle position as a function of time, which is perfect for my needs for making a visual simulation but the problem is those functions only works for angles smaller than 10, but I should be able to simulate from any angle. Example of a equation that only works for small angles:

Source: http://hyperphysics.phy-astr.gsu.edu/hbase/pend.html#c2

And the equations that should work for any angle (Amplitude) are too complicated as it involves differential equations, and derivatives. I don't know how to implement these in C#. Example of a equation that I think would work but I don't know how to use:

Source: http://www.sbfisica.org.br/rbef/pdf/070707.pdf (Equation number 32)

the problem of this last equation is the "sn" that is Jacobi elliptic function sn(u;m) u, and I don't know how to use in C#

Can someone help? maybe with another equation that I could use programmatically, or helping me understand how I could use this last one if it would really works.

  • Could also just [rotate a position around an origin](http://stackoverflow.com/q/13695317/1218281), not that difficult. (But relying on trigonometry and not actual physics) – Cyral Apr 24 '15 at 01:54
  • It would not work as the simulator has to accept any Pendulum length and any mass, and any starting angle. – Carlos Goncalves Apr 24 '15 at 01:55
  • There is a good article at http://www.codeproject.com/Articles/566614/Elliptic-integrals which looks at exactly this problem, and ends up approximating the elliptic integral with a Maclaurin series. – Hugh Bothwell Apr 25 '15 at 01:36

1 Answers1

0

If you want to simulate the pendulum, you don't need the exact solution. The only you need is a sufficiently good approximation at every step of your simulation, combined with sufficient steps. This is similar to approximating a circle with a sufficiently large number of segments, each of them, tangent to the ideal circle.

Now, consider your pendulum has a deviation of theta degrees (or radians) from the vertical as depicted below:

enter image description here

The mass m will have a weight of m * g, where g is the gravity acceleration. Now, let's approximate the angle alpha where the pendulum will move in the next dt seconds (dt is the duration of one step, so dt is just a fraction of a second).

Since the acceleration on the tangent direction is g * cos(theta) we can approximate the tangent distance the pendulum would travel in dt seconds as if the acceleration were constant during this lapse:

d = v * dt + g * sin(theta) (dt)^2 / 2

where v is the tangential speed of the pendulum at the angular position theta. Now we can calculate alpha as

alpha = arcsin(d / r)

where r is the radius. Thus, the only that remains is to update the value of v so we can repeat the same in the next step. Here is how

v := v + g * sin(theta) * dt

Of course, when the pendulum starts you can initialize v = 0.

I haven't tried this myself, so please, let me know if this "simulated" approach worked for you. Good luck!

Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51
  • This is exactly the approach given in his "methods that only work for small angles" link. – Hugh Bothwell Apr 25 '15 at 00:58
  • Yes, but with a difference. In my (it isn't "mine" but..) approach the total angle `theta` doesn't have to be small, it can be anything. Only the differential `alpha` must be small, which requires `dt` to be small enough. The effect is the discretization of the movement into small steps where the mathematical equations are simple and easy to solve. – Leandro Caniglia Apr 25 '15 at 16:00