Computers and computational modeling provide a powerful (and almost necessary) tool in modern scientific research and engineering work. While analytic (i.e., paper and pencil) solutions do exist for some problems, computational modeling allows you to create 3D visualizations, incorporate more complex behavior, model millions of particles at the same time, analyze massive amounts of data, or simply solve repetitive calculations. In addition to solving analytic problems, this course will have you working with simple computational models in VPython (a Python-based programming language that specializes in visualization). You will develop these computational models in class with the help of your classmates and the guidance of instructors. In these notes, you will read about how to write your programs so that they follow a common structure, which will make it easier to write new programs in the future.
There are 5 major components that you will repeat in each program that you write:
This video will walk you through how to model a fancart on a track in VPython.
Below is the code that was written in the lecture video above.
from visual import * from physutil import * #Set up windows scene.width = 1024 scene.height = 768 #Objects track = box(pos=vector(0,0,0), size=vector(10,0.1,1), color=color.white) fancart = box(pos=vector(-4.75,0.15,0), size=vector(0.5,0.19,0.3), color=color.red) fancartMotionMap = MotionMap(fancart, 10, 10, markerScale=2) #Parameters and Initial Conditions fancart.mass = 0.3 fancart.p = vector(0.15,0,0) #Time and time step dt = 0.5 t = 0 #Calculation loop while t < 10: rate(25) Ffan = vector(0.025,0,0) fancart.p = fancart.p + Ffan*dt fancart.pos = fancart.pos + (fancart.p/fancart.mass)*dt fancartMotionMap.update(t, fancart.p) t = t + dt