<s> from __future__ import print_function , division <EOL> from visual import * <EOL> scene . title = '<STR_LIT>' <EOL> scene . height = scene . width = <NUM_LIT> <EOL> g = <NUM_LIT> <EOL> M1 = <NUM_LIT> <EOL> M2 = <NUM_LIT:1.0> <EOL> L1 = <NUM_LIT:0.5> <EOL> L2 = <NUM_LIT:1.0> <EOL> I1 = M1 * L1 ** <NUM_LIT:2> / <NUM_LIT:12> <EOL> I2 = M2 * L2 ** <NUM_LIT:2> / <NUM_LIT:12> <EOL> d = <NUM_LIT> <EOL> gap = <NUM_LIT:2> * d <EOL> L1display = L1 + d <EOL> L2display = L2 + d / <NUM_LIT:2> <EOL> hpedestal = <NUM_LIT> * ( L1 + L2 ) <EOL> wpedestal = <NUM_LIT:0.1> <EOL> tbase = <NUM_LIT> <EOL> wbase = <NUM_LIT:8> * gap <EOL> offset = <NUM_LIT:2> * gap <EOL> top = vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> scene . center = top - vector ( <NUM_LIT:0> , ( L1 + L2 ) / <NUM_LIT> , <NUM_LIT:0> ) <EOL> theta1 = <NUM_LIT> <EOL> theta2 = <NUM_LIT> <EOL> theta1dot = <NUM_LIT:0> <EOL> theta2dot = <NUM_LIT:0> <EOL> pedestal = box ( pos = top - vector ( <NUM_LIT:0> , hpedestal / <NUM_LIT> , offset ) , <EOL> height = <NUM_LIT> * hpedestal , length = wpedestal , width = wpedestal , <EOL> color = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.5> ) ) <EOL> base = box ( pos = top - vector ( <NUM_LIT:0> , hpedestal + tbase / <NUM_LIT> , offset ) , <EOL> height = tbase , length = wbase , width = wbase , <EOL> color = pedestal . color ) <EOL> axle = cylinder ( pos = top - vector ( <NUM_LIT:0> , <NUM_LIT:0> , gap / <NUM_LIT> - d / <NUM_LIT> ) , axis = ( <NUM_LIT:0> , <NUM_LIT:0> , - offset ) , radius = d / <NUM_LIT> , color = color . yellow ) <EOL> frame1 = frame ( pos = top ) <EOL> bar1 = box ( frame = frame1 , pos = ( L1display / <NUM_LIT> - d / <NUM_LIT> , <NUM_LIT:0> , - ( gap + d ) / <NUM_LIT> ) , size = ( L1display , d , d ) , color = color . red ) <EOL> bar1b = box ( frame = frame1 , pos = ( L1display / <NUM_LIT> - d / <NUM_LIT> , <NUM_LIT:0> , ( gap + d ) / <NUM_LIT> ) , size = ( L1display , d , d ) , color = color . red ) <EOL> axle1 = cylinder ( frame = frame1 , pos = ( L1 , <NUM_LIT:0> , - ( gap + d ) / <NUM_LIT> ) , axis = ( <NUM_LIT:0> , <NUM_LIT:0> , gap + d ) , <EOL> radius = axle . radius , color = axle . color ) <EOL> frame1 . axis = ( <NUM_LIT:0> , - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> frame2 = frame ( pos = frame1 . axis * L1 ) <EOL> bar2 = box ( frame = frame2 , pos = ( L2display / <NUM_LIT> - d / <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) , size = ( L2display , d , d ) , color = color . green ) <EOL> frame2 . axis = ( <NUM_LIT:0> , - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> frame1 . rotate ( axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) , angle = theta1 ) <EOL> frame2 . rotate ( axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) , angle = theta2 ) <EOL> frame2 . pos = top + frame1 . axis * L1 <EOL> dt = <NUM_LIT> <EOL> t = <NUM_LIT:0.> <EOL> C11 = ( <NUM_LIT> * M1 + M2 ) * L1 ** <NUM_LIT:2> + I1 <EOL> C22 = <NUM_LIT> * M2 * L2 ** <NUM_LIT:2> + I2 <EOL> while True : <EOL> rate ( <NUM_LIT:1> / dt ) <EOL> C12 = C21 = <NUM_LIT:0.5> * M2 * L1 * L2 * cos ( theta1 - theta2 ) <EOL> Cdet = C11 * C22 - C12 * C21 <EOL> a = <NUM_LIT> * M2 * L1 * L2 * sin ( theta1 - theta2 ) <EOL> A = - ( <NUM_LIT> * M1 + M2 ) * g * L1 * sin ( theta1 ) - a * theta2dot ** <NUM_LIT:2> <EOL> B = - <NUM_LIT> * M2 * g * L2 * sin ( theta2 ) + a * theta1dot ** <NUM_LIT:2> <EOL> atheta1 = ( C22 * A - C12 * B ) / Cdet <EOL> atheta2 = ( - C21 * A + C11 * B ) / Cdet <EOL> theta1dot += atheta1 * dt <EOL> theta2dot += atheta2 * dt <EOL> dtheta1 = theta1dot * dt <EOL> dtheta2 = theta2dot * dt <EOL> theta1 += dtheta1 <EOL> theta2 += dtheta2 <EOL> frame1 . rotate ( axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) , angle = dtheta1 ) <EOL> frame2 . pos = top + frame1 . axis * L1 <EOL> frame2 . rotate ( axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) , angle = dtheta2 ) <EOL> t = t + dt </s>
