Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

http://techforcurious.website/simulation-of-pendulum-vpython-tutorial-visual-python/

from visual import*
display(width=600,height=600,center=vector(0,12,0),background=color.white)
g=9.8 # acceleration due to gravity
bob=sphere(pos=vector(5,2,0),radius=0.5,color=color.blue)
pivot=vector(0,20,0)
roof=box(pos=pivot,size=vector(10,0.5,10),color=color.green)
rod=cylinder(pos=pivot,axis=bob.pos-pivot,radius=0.1,color=color.red)
t=0 # time 
dt=0.01 # time interval 
l=mag(bob.pos-pivot) # length of pendulum
cs=(pivot.y-bob.pos.y)/l # calculation of cos(theta) 
theta=acos(cs) # angle with vertical direction
vel=0.0 # angular velocity
while (t<100):
  rate(100) # maximum 100 calculations per second
  acc=-g/l*sin(theta) # updating of angular acceleration
  theta=theta+vel*dt # updating of angular position
  vel=vel+acc*dt # updating of angular velocity
  bob.pos=vector(l*sin(theta),pivot.y-l*cos(theta),0) # cal. position
  rod.axis=bob.pos-rod.pos # updating other end of rod of pendulum
  t=t+dt # updating time
Comment

PREVIOUS NEXT
Code Example
Python :: plot line2d on axis 
Python :: credential not provided when i try to sign up a new user django 
Python :: countvectorizer remove stop words 
Python :: hack instagram account with python 
Python :: how to send variable to python using xlwings 
Python :: grandest staircase foobar 
Python :: python directed graph 
Python :: os.system ignore output 
Python :: pagerank formula 
Python :: pandas : stratification (mean) 
Python :: declare variable in python 
Python :: how to delete a row based on a criteria in python datafram 
Python :: run exe for python and wait until finish 
Python :: task orchestration framework 
Python :: python loop invalid input 
Python :: django import excel file from same directory 
Python :: grepper how to use fraction 
Python :: python counter infinite series 
Python :: how to take multiple input python 
Python :: text to qr code python 
Python :: set environment variable heroku django 
Python :: search number is complete or no python 
Python :: blockchain.py 
Python :: Can the string find method be used to search a list? 
Python :: least square fit straight line python 
Python :: tanimoto coefficient rdkit 
Python :: matplotlib annotate align center 
Python :: serialization in python 
Python :: inverting a dictionary 
Python :: syntax error in python 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =