Hi all,(adsbygoogle = window.adsbygoogle || []).push({});

I'm having some problems trying to simulate a pendulum in C++. I am using x,y coordinates (and not angular coordinates, velocity...) to use the same method than all other dynamics in my program which are:

- Compute sum of all forces

- a = sum(F)

- v += a

- position += v

For the pendulum I'm getting quiet the good movement oscillating from right to left and reverse but the bob is "sinking" little by little.

First Method: Force = Tension + Gravity

Second Method: Force = mg.sin (alpha)Code (Text):

// Weight Force

fWeight->set (0, mg); // x,y of force vector

// Tension Force: T=-mg.cos(alpha) in tangential/radial coordinates

// so back in my original coordinates

double Fx = mg*sin(alpha)*cos(alpha);

double Fy = -mg*cos(alpha)*cos(alpha);

fTension->set (Fx, Fy);

// Result Net Force

fResult->set (fWeight->xV() + fTension->xV(), fWeight->yV() + fTension->yV());

As I said the 2 methods give the same result: oscillating but falling...Code (Text):

fResult->set (mg*sin(alpha), AngleRad (alpha));

Can you tell me if the way I am computing the total forces is correct ? If you notice something wrong tell me !

Thanks

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Pendulum in C++

**Physics Forums | Science Articles, Homework Help, Discussion**