- #1

iox

- 4

- 0

Hi all,

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)

As I said the 2 methods give the same result: oscillating but falling...

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

Thanks

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

Code:

```
// 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());
```

Second Method: Force = mg.sin (alpha)

Code:

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

As I said the 2 methods give the same result: oscillating but falling...

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

Thanks

Last edited: