Here is the full, unabbreviated derivation of the equations of motion for a double pendulum using Lagrangian mechanics, written by AI (Gemini).
In physics and mathematics, the dot above a variable is Newton’s notation for the time derivative. It is a shorthand way of saying how much this value is changing with respect to time.
θ (Theta): The Angle (Position).
θ˙ (Theta-dot): The Angular Velocity (How fast the angle is changing).1 This is the a1_v and a2_v in your JavaScript code.2
θ¨ (Theta-double-dot): The Angular Acceleration (How fast the velocity is changing). This is the a1_a and a2_a that your getAccelerations function calculates.
1. Coordinate Transformation
We define the positions (x1,y1) and (x2,y2) of the two masses in terms of the angles θ1 and θ2. We assume the y-axis points downwards.
x1=l1sinθ1
y1=l1cosθ1
x2=l1sinθ1+l2sinθ2
y2=l1cosθ1+l2cosθ2
2. The Lagrangian (L)
The Lagrangian is the difference between the Kinetic Energy (T) and the Potential Energy (V).
Kinetic Energy (T):
Summing T=21mv2 for both masses (where v2=x˙2+y˙2):
By solving the above linear system for θ¨1 and θ¨2, we obtain the formulas used in the getAccelerations function:
Acceleration of the first arm (θ¨1):
θ¨1=l1(2m1+m2−m2cos(2θ1−2θ2))−g(2m1+m2)sinθ1−m2gsin(θ1−2θ2)−2sin(θ1−θ2)m2(θ˙22l2+θ˙12l1cos(θ1−θ2))
Acceleration of the second arm (θ¨2):