VPython Physics 1211k
1. Here is a somewhat more sophisticated program that recreates one of your experiments – a cart rolling up a ramp and back down. Particularly pay attention to the components of the acceleration.
from visual import *
#control the dimensions of the animation window. Turn off autoscaling. Then set the window to show 20 meters
#in each direction. Then set the actual physical size of the animation window on the screen
scene.autoscale = False
scene.range = 20
#scene.width = 640
#scene.height = 480
#scene.align = 'left'
#set up some constants
g = 9.8
theta = pi*20/180
#create a particle to represent the center of mass. Velocity and acceleration are not properties of spheres
#but you can add them as properties or your sphere by just stating that they exist
cart = sphere(pos=vec(-5,0,0), radius = 0.7, color = color.yellow)
cart.v = vec(10*cos(theta),10*sin(theta),0)
cart.a = vec(-g*sin(theta)*cos(theta), -g*(sin(theta))**2,0)
#time step
dt = 0.05
t =
#animation loop
while cart.pos.x >= -5:
rate(30)
#update velocity, position and time
cart.v = cart.v + cart.a*dt
cart.pos = cart.pos + cart.v*dt
t = t + dt
a. First, add velocity and acceleration vectors to the object that change magnitude and direction appropriately.
b. Make graphs of position versus time and velocity versus time. You should create two graphs, one of which plots both the x and y components of position vs. time, and the other plots x and y components of velocity vs. time.
2. The VPython coordinate system is origin at the center of the animation window, x to the left and y up and you can’t change it. But what you really want in problem 1 is a coordinate system like your motion detector with x pointing up the ramp. You’ll have to do a little trig to figure that out from the components you have. Once you do, use that to redo problem one with a single position graph plotting position up the ramp and a single velocity graph plotting velocity along the ramp.
I'm having difficulty making graphs in VPython/ GlowScript 2.7, please help!
Here is a simple script of making graphs in python 2.7
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
sns.set_style("whitegrid")
sns.set_context("notebook", font_scale=0.75, rc={"lines.linewidth":
1.0})
fileName = 'plot.dat'
data = np.genfromtxt(fileName,skip_header=0,usecols=(0,2))
plt.plot(data[:,0],data[:,1],'-',markersize=5,
label='single')
plt.xlim([0,10])
plt.ylim([0,10])
plt.title('plot')
plt.xlabel(r'x axis')
plt.ylabel(r'y axis')
plt.legend()
plt.savefig('plot.pdf')
plt.show()
Get Answers For Free
Most questions answered within 1 hours.