Why is my pendulum simulation not working

Started by
6 comments, last by EulerianPendulum 4 years, 4 months ago

Hello,

consider following diagram of vectors to derive the vector representing the acceleration:

I am using the eulerian method to numerically intergrate the formula of acceleration shown in the diagram.

Here is the whole c#-class

        public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Vector2 center = new Vector2(500, 250);

        Vector2 bobPosition = new Vector2(450, 250);
        Vector2 bobVelocity = new Vector2(0, 0);


        Vector2 gravitationalForce = new Vector2(0, 10);


        private void Form1_Load(object sender, EventArgs e)
        {
            this.Size = new Size(1000, 1000);

            this.DoubleBuffered = true;
            this.Paint += new PaintEventHandler(draw);
            Application.Idle += new EventHandler((a, b) =>
            {

                if (!mousdown)
                {

                    Vector2 dir = bobPosition - center;
                    dir.Normalize();
                    Vector2 force = new Vector2(gravitationalForce.X, gravitationalForce.Y);
                    force.Normalize();

                    float forceMagnitude = gravitationalForce.Length();
                    float theta = Vector2.Dot(dir, force);

                    dir = -dir;

                    Vector2 acceleration = gravitationalForce + dir * theta * (forceMagnitude);


                    bobVelocity += acceleration * 0.05f;
                    bobPosition += bobVelocity * 0.05f;



                }

                this.Invalidate();
            });



    
        }


        private void draw( object sender, PaintEventArgs e)
        {

            Graphics g = e.Graphics;

            g.FillEllipse(Brushes.Red, center.X - 25f, center.Y - 25f, 50, 50);
            g.FillEllipse(Brushes.Blue, bobPosition.X - 12.5f, bobPosition.Y - 12.5f, 25, 25);

            g.DrawLine(Pens.Black, center.X, center.Y, bobPosition.X, bobPosition.Y);


        }

        bool mousdown;

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            mousdown = true;
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!mousdown)
                return;

            bobPosition = new Vector2(e.X, e.Y);
            Invalidate();

        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {

            mousdown = false;


        }
    }

But the simulation is just wrong: The bob keeps falling down without ever being pushed towards center. Why is it?

Is my diagram wrong?

Best regards

Advertisement

Not sure where you're getting that diagram from. For a pendulum you have two forces acting on the bob: the gravitational force which always acts downwards and a tension force acting in the direction from the bob to the center.

If you have a rigid pendulum rod (ie it always has the same length) then the tension force is constant, and when the pendulum is vertical it is not accelerating (so no net force) so we know that the tension force has the same magnitude as the gravitational force.

@rulerofnothing I know' mate, the formula given above is true for all extremal conditions.

Consider:

a = g + (-d * |g| * theta) with a, g and d are vectors.

Let theta be 1 (this happens exactly then, when the pendulum is vertical) the acceleration becomes

a = (0, -9.81) + ((0, 1) * 9.81 * 1) = (0, 0).

But something is still wrong….

When I said the tension force is constant, this obviously means that it does not change with the pendulum angle, and so your formula is incorrect. Consider that if the pendulum rod is horizontal then according to your formula there is only the gravitational force acting downwards, and this is obviously not the case.

RulerOfNothing said:

When I said the tension force is constant, this obviously means that it does not change with the pendulum angle, and so your formula is incorrect. Consider that if the pendulum rod is horizontal then according to your formula there is only the gravitational force acting downwards, and this is obviously not the case.

I don't see how the tension force is constant if the speed of the pendulum is not constant. When the pendulum swings as far as it can in one direction, its speed will reach zero briefly before going back in the opposite direction. At this point the tension force should be zero according to the relationship between tangential speed and centripital force: F=m*v^2/r. The tension force should be greatest at the bottom of the swing, where its tangential speed is greatest.

More supporting evidence

According to the supporting evidence link the centripetal force for a pendulum is the sum of the tension force and the component of the gravitational force acting along the direction of the pendulum rod, so I was wrong and the tension force is not constant (and not equal in magnitude to the gravitational force when the bob is at the bottom)

RulerOfNothing said:
and not equal in magnitude to the gravitational force when the bob is at the bottom

How is that? If the pendulum starts vertical,the acceleration should be zero, shouldn't it?

This happens only if either the tension force and gravitational force cancel each other out .. or if the velocity is somehow involved in the acceleration.

This topic is closed to new replies.

Advertisement