Sitemap
Rhett Allain

Rhett Allain

Physics faculty, science blogger of all things geek. Technical Consultant for CBS MacGyver and MythBusters. WIRED blogger.

Member-only story

Python Physics: Motion in 3D and Animations

14 min read1 day ago
Press enter or click to view image in full size
decorative art. here are three outputs from vpython. left: sphere, middle: box, right: projectile motion
VPython objects: The sphere() and the box()

Continuing my series on python for introductory physics. In this chapter, we are going to go over the stuff that makes Web VPython so awesome — 3D motion and animations.

If you are keeping up, here are the previous chapters:

OK, let’s get to it.

Vectors

I know what you are going to say, “a vector has magnitude and direction”. I mean, that’s not wrong — but that’s not the version I like. Here’s how I describe vectors. My preferred definition is that a vector is a variable with more than one number. Three dimensional vectors have three numbers. In Cartesian coordinates, we can describe a position as the following vector (I will write it three different ways).

\vec{r} = x\hat{x}+y\hat{y}+z\hat{z} && \vec{r}=x\hat{i}+y\hat{j}+z\hat{k} && \vec{r}=<x,y,z>

These are all the same things, but I prefer the last version.

If we want to animate objects in 3D, we obviously need three dimensional vectors. Good news! Vectors are built into VPython. Here’s some quick vector stuff in VPython.

--

--

Rhett Allain
Rhett Allain

Written by Rhett Allain

Physics faculty, science blogger of all things geek. Technical Consultant for CBS MacGyver and MythBusters. WIRED blogger.