The purpose of this lab is to become acquainted with the python programming language and the visual version of the language Vpython. This lab will consist of using tutorials from YouTube in conjunction with the lab handout to achieve the following tasks:
- How to use VIDLE
- The layout for a basic program
- How to create 3-D objects such as spheres and arrows
- How to scale
- How to program and use vectors
For the first part of the lab, the goal was to import the visual python libraries. This was done using the command from visual import*. The next line to follow is a fail safe for the program to run even if it was programmed in an older version of Vpython, the line was from future import*. This serves as the basic framework for a program in Vpython.
The next step in the lab was to create three dimensional objects such as spheres and arrows. The tutorials from http://www.youtube.com/VPythonVideos were used in conjunction with the lab handout. The tutorial led to the creation of the following code and image.
#Physics 4A Lab: Introduction to Vpython
#April 9th 2012
#Chris Cosio
#This is an introductory program writen as an introduction to python.
from __future__ import division
from visual import*
a=sphere(pos=vector(-1,0,0), radius = 0.5, color = color.green)
b=sphere(pos=vector(1,1,0), radius = 0.5, color = color.green)
c=sphere(pos=vector(1,-1,0), radius = 0.5, color = color.green)
arrow(pos=vector(-1,0,0), axis=c.pos-a.pos, color = color.red)
arrow(pos=vector(1,1,0), axis=a.pos-b.pos,color = color.red)
arrow(pos=vector(1,-1,0), axis=b.pos-c.pos,color = color.red)
The next step in the lab was to scale the vectors. Following the handout and the tutorials, the next code and image was generated. Furthermore, print statements were added for the position of each sphere.
#Physics 4A Lab: Introduction to Vpython
#April 9th 2012
#Chris Cosio
#This is an introductory program writen as an introduction to python.
from __future__ import division
from visual import*
a=sphere(pos=vector(-2,0,0), radius = 0.5, color = color.green)
b=sphere(pos=vector(1,1,0), radius = 0.5, color = color.green)
c=sphere(pos=vector(1,-1,0), radius = 0.5, color = color.green)
arrow(pos=vector(-2,0,0), axis=c.pos-a.pos, color = color.red)
arrow(pos=vector(1,1,0), axis=a.pos-b.pos,color = color.red)
arrow(pos=vector(1,-1,0), axis=b.pos-c.pos,color = color.red)
print(a.pos)
print(b.pos)
print(c.pos)
This last set of code concluded the lab. In the near future for this class, it will be possible to model situations with this language. For example, If a person wish to model a collision between four different objects at the same time, it would be possible to to use spheres and vectors to model the collision. Programing the aforementioned scenario has the advantages of repeatability and reliability. If a person were to set up a physical version of that collision, there would be many issues with repeating the experiment exactly the same every time. Computational modeling takes out some of those errors.
No comments:
Post a Comment