VP_2212intro_to_vpython

VP_2212intro_to_vpython - Introduction to 3D modeling 1...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to 3D modeling 1 Objectives In this course you will construct computer models to: Visualize motion in 3D Visualize field quantities like the electric and magnetic fields in 3D Do calculations based on fundamental principles to predict the motion of interacting objects Animate the predicted motions in 3D To do this you will use a 3D programming environment called VPython. In this lab you will learn: How to use IDLE, the interactive editor for VPython How to structure a simple computer program How to create 3D objects such as spheres and arrows How to use vectors in VPython 2 Overview of a Computer Program A computer program consists of a sequence of instructions. The computer carries out the instruc- tions one by one, in the order in which they appear, and stops when it reaches the end. Each instruction must be entered exactly correctly (as if it were an instruction to your calculator). If the computer encounters an error in an instruction (such as a typing error), it will stop running and print a red error message. A typical program has four sections: Setup statments Definitions of constants Creation of objects Calculations to predict motion or move objects (these may be repeated) 3 Using IDLE to create a program Find an icon called IDLE for VPython on the Desktop. Double click the IDLE icon. This starts IDLE, which is the editing environment for VPython. 1 3.1 Starting a program: Setup statements Enter the following two statements in the IDLE editor window: from future import division from visual import * Every VPython program begins with these setup statements. The first statement (from space un- derscore underscore future underscore underscore space import space division) tells the Python language to treat 1/2 as 0.5. Without the first statement, the Python programming language does integer division with truncation and 1/2 is zero! The second statement tells the program to use the 3D module (called visual). Before we write any more, lets save the program: In the IDLE editor, from the File menu, select Save. Save to the P: \ drive in your prism folder. You can save the file and access it from anywhere. Give it the name vectors.py. YOU MUST TYPE the .py file extension - IDLE will NOT automatically add it. Without the .py file extension IDLE wont colorize your program statements in a helpful way. 3.2 Creating an object In the next section of your program you will create 3D objects: Now tell VPython to make a sphere. On the next line, type: sphere() This statement tells the computer to create a sphere object. Run the program by pressing F5 on the keyboard. Two new windows appear in addition to the editing window. One of them is the 3-D graphics window, which now contains a sphere....
View Full Document

This note was uploaded on 03/04/2012 for the course PHYS 2212 taught by Professor Jarrio during the Spring '10 term at Central GA Tech.

Page1 / 11

VP_2212intro_to_vpython - Introduction to 3D modeling 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online