spring model....i want to get the program to return the value of the period of the motion of the pendulum
i have tried putting this outside the loop
oldVelocity = vector(0,0,0)
and this inside the loop before v:
oldVelocity = m.v
with print statement:
if oldVelocity.y/m.v <0:
print ("time = ",t)
but i get this error:
oldVelocity = m.v
AttributeError: 'int' object has no attribute 'v'
i have also tried:
oldVeloctiy = v
inside loop and changing the
if statement to
if oldVelocity.y/v <0:
print ("time = ",t)
here is my code:
from visual import*
from visual.graph import*
scene.background = color.white
L_o = 0.17
rod = cylinder(pos=(-.5,-.5,0),axis=(0,1,0),radius=.005,color=(166/255,172/255,182/255))
bar = cylinder(pos=(-.5,.4,0),axis=(.5,0,0), radius=.005,color=(166/255,172/255,182/255))
weight = cylinder (pos= (.5, -.6, 0), length=.05, radius=.02, color=(181/255,166/255,66/255))
spring = helix(pos=bar.pos+(.25,0,0), axis=(0,L_o,0), radius=.0093, length=.3, coils= 20)
platform = box(pos = ( -.1, -.5 , 0), axis = (0,1,0),height = .9, length = .001, width = .01, color = color.black)
m = 1
g = vector(0, -9.8, 0 )
Fg = m * g
d = .04
v = vector(0, 0 , 0)
p = m * v
k = 203
t = 0
dt = .01
r = vector(-0.25, 0.25, 0)
oldVelocity = vector (0,0,0)
while 1:
rate(1/dt)
Fd = -d * mag(v) * norm(v)
L = r - spring.pos
Lo = L_o * norm(L)
s = L - Lo
Fsp = -k * s
Fnet = Fd + Fg + Fsp
p = p + Fnet * dt
oldVelocity = m.v
v = p / m
r = r + v * dt
weight.pos = r
weight.axis = norm(L) * 0.05
spring.axis = L
t = t + dt
if oldVelocity.y/m.v <0:
print ("time = ",t)