# Double Pendulum in Geometry Nodes

I want to simulate a a double pendulum in geometry nodes.

I'm using this derivation

from this site.

However, the simulation is just a bit off. Either it will eventually just start spinning around in a circle

Or it dampens quickly and slows down

I've tried adjusting the timestep (g) but even with small time steps it runs into this behavior.

Essentially my logic tree is as follows.

• compute change in angular velocity w1' and w2'
• add this to the current angular velocity w1 and w2
• add this to the current angles theta1 and theta2
• Do this four times for the runge-kutta
• Weight the results for RK
• Send those values to the next sim step

I don't know if I missed a single value somewhere that messed it up but I would love to see if some else can crack this for me.

Here is the file if you wanna take a look at the labeled spaghetti

• Have you tested the maths is correct? I would calculate outputs for some inputs outside of geonodes first and then test in geonodes if I get the same values. Considering you ask for double pendulum implementation, that seems to already be done here so it's a duplicate then? Commented Jan 15 at 15:54
• @MarkusvonBroady I'll give the maths a check tomorrow. Also that example you posted is not in geometry nodes. Commented Jan 15 at 18:01
• Beware that g is the gravitational constant, not the time step. Commented Jan 18 at 20:24

Found the issue. At the advice of @Markus von Broady I checked the outputs against raw caluclations of each section and found a divergence. I then kept narrowing it down until I found my error.

I accidentally had m2 plugged into the multiplier rather than the addendum section on my w2 setup.

Numerical unstable behaviour seems related to a confusion between $$g$$, the gravitational constant as defined in the referenced page, and the time step $$dt$$ of Runge-Kutta schemes. As it is, a parameter in the GeometryNodes graph such as $$dt$$ controlling stability is missing.
Following is a proposal not as sophisticated as what you try to do, but it could be a starting point to achieve your goal. Instead of RK4, it relies on a much simpler integration scheme in time named Euler method, sometime labelled RK1. Using your notations, advancing the solution from frame/time $$t^n$$ to frame/time $$t^{n+1}$$, it reads: $$\omega' = \frac{d\omega}{dt} = \frac{d^2 \theta}{dt^2}$$ $$\omega^{n+1} = \omega^{n} + \omega' \times dt$$ $$\theta^{n+1} = \theta^{n} + \omega^{n+1} \times dt$$ The associated graph, coded in the original NodeGroup K1, is: It is called only one time, instead of four times in the original graph, in the Simulation Zone (not shown). NB: The value of $$dt$$ is hard-coded in an Input/Constant/Value node; it should come from the Group Input node for flexibility...
This setup is illustrated with the same length and mass for both pendulum masses, put at the same small angle at $$t=0$$. As expected, it behaves like a single stable pendulum.