|
Visual Python
Visual Python (home page: http://vpython.org/) provides a small and simple library to create 3d scenes and animations quickly and efficiently. Often, this is useful to create visualisations of processes and simulation processes and results.
Note: Visual Python is not part of Enthought Python and needs to be installed separately.
Exercises
Familiarize yourself with visual python through the example programs,
which are also explained in the relevant section in
the Lecture notes (13.2 Visual Python).
If you like a more detailed introduction, you can find introductory videos on YouTube, and the official visual python homepage.
Write a function mypath() that computes a trajectory through 3d space (i.e. a function
f(t) -> (x,y,z), that takes the current time t as input and returns 3d vector (of type tuple or list).
Write visual python code to show a sphere whose position is given by f(t).
If you cannot think of suitable curve, try:
t -> ( cos(2*pi*t), sin(2*pi*t), t )
Extend function mypath() to also show the trace of the object
(look at visual.curve and append the position of each time step
to the trace object (see vpythondemo4.py)
Study how this ordinary differential equation integration example pendulum.py of a (damped) harmonic
oscillator is translated into this time-animated version pendulum_visual.py (without damping). If you haven't done so yet, you may want to learn about integration of systems of ordinary differential equations. (You can start with section 14.4 Solving ordinary differential equations in the lecture notes although this is extremely brief at the moment.)
Output of pendulum.py (pendulum.png, pendulum.pdf):
Try to vary parameters (initial conditions, mass spring constant, etc) then run the code again.
Can you predict the effect of your changes?
Extend this example, for example
- introduce friction in the visual example
- allow the pendulum on the spring to move in 2 or 3 dimensions
- or implement some other dynamic system you are interested in with
visual python visualisation.
There is nothing to submit for this lab.
|