Implement hamiltonian simulation
This commit is contained in:
parent
daeff1c461
commit
874edf17f2
20
Main.hs
20
Main.hs
@ -32,5 +32,23 @@ rod = color rodColor $ line [ (0, 0), (0, negate rodLength) ]
|
||||
particle = color particleColor $ circleSolid particleRadius
|
||||
rotateRadians = rotate . radToDeg . negate
|
||||
|
||||
step _ _ = nextState
|
||||
nextState state = State (theta state + thetaDot state)
|
||||
(pTheta state + pThetaDot state)
|
||||
(phi state + phiDot state)
|
||||
(pPhi state + pPhiDot state)
|
||||
thetaDot state
|
||||
= (6 * (2 * pTheta state - 3 * cos (theta state - phi state) * pPhi state))
|
||||
/ (particleMass * rodLength ^ 2 * (16 - 9 * cos (theta state - phi state) ^ 2))
|
||||
phiDot state
|
||||
= (6 * (8 * pPhi state - 3 * cos (theta state - phi state) * pTheta state))
|
||||
/ (particleMass * rodLength ^ 2 * (16 - 9 * cos (theta state - phi state) ^ 2))
|
||||
pThetaDot state
|
||||
= (- 1 / 2) * particleMass * rodLength ^ 2
|
||||
* (thetaDot state * phiDot state * sin (theta state - phi state) + 3 * g * sin (theta state) / rodLength)
|
||||
pPhiDot state
|
||||
= (1 / 2) * particleMass * rodLength ^ 2
|
||||
* (thetaDot state * phiDot state * sin (theta state - phi state) - g * sin (phi state) / rodLength)
|
||||
|
||||
window = InWindow "Double Pendulum" (800, 800) (100, 100)
|
||||
main = display window white (render initialState)
|
||||
main = simulate window white framesPerSecond initialState render step
|
||||
|
Loading…
x
Reference in New Issue
Block a user