lab7_unfinished

 avatar
unknown
python
5 days ago
766 B
3
Indexable
Web VPython 3.2

from visual import *
#constants
L0 = 8
theta0 = 10 * pi/180
g = 9.8
m = 5
t = 0
dt = 0.01

anchor = sphere(pos = vec(0,0,0), radius = 0.2 , color = color.yellow)
ball = sphere(pos = anchor.pos + vec(0,-L0,0), color = color.red, mass = m, v = vec(0,0,0), radius = 0.5)

string = helix(pos = anchor.pos, axis = ball.pos - anchor.pos, radius = 0.2, color = color.orange)

ball.theta = theta0
ball.omega = 0

ball.p = 0

while t < 10:
    rate(150)
    
    
    F = m * -g *sin(ball.theta)
    
    ball.p = ball.p + F*dt
    
    ball.omega = ball.p/ball.mass
    
    ball.theta = ball.theta + ball.omega * dt
    
    ball.pos = anchor.pos + vec(L0 * sin(ball.theta), -L0 * cos(ball.theta),0)
    
    string.axis = ball.pos - anchor.pos
    t+= dt
Editor is loading...
Leave a Comment