Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Vtk /TCL question -Data visualization The vtkSphereSource class generates a poly

ID: 3606015 • Letter: V

Question

Vtk /TCL question -Data visualization

The vtkSphereSource class generates a polygonal model of a sphere. create a program to display a white sphere. Set the ambient and diffuse intensities to 0.5. Then add a for-loop to this program that adjusts the ambient and diffuse color of this sphere so that as the loop progresses, the diffuse color goes from red to blue, and the ambient color goes from blue to green. You might also try adjusting other lighting parameters such as specular color, ambient, diffuse, and specular intensity.

Using the code developed in step 1, add code to display the sphere with a light source positioned at (1, 1, 1). Then extend this program by adding a for-loop that will adjust the active camera’s clipping range so that increasing portions of the interior of the sphere can be seen. By increasing the first value of the clipping range, you will be adjusting the position of the front clipping plane. Once the front clipping plane starts intersecting the sphere, you should be able to see inside of it. The default radius of the vtkSphereSource is 0.5, so make sure that you adjust the clipping range in increments less than 1.0.

Explanation / Answer

1 Overview

VPython is a programming language that is easy to learn and is well suited to creating 3D interactive models of

physical systems.

2 Your first program

>

Sign in at glowscript.org, then click to go to your program space. Click “Create New Program” and choose a

name for your program; any spaces and underscores will be deleted from the name.

>

You will see a blank edit window with a header line that says “GlowScript X.Y VPython”.

>

As the second line of your program, type the following statement:

sphere()

3 Running the program

>

Now run your program by clicking “Run this program”. (You can also press Ctrl-1 to run the program in the same

window, or click Ctrl-2 to run the program in a separate window.)

When you run the program, you should see a white 3D sphere.

>

In the VPython window, hold down the left+right buttons on a two-button mouse (or the Alt key) and move the

mouse. You should see that you are able to zoom into and out of the scene.

>

Now try holding down the right mouse button (or the Ctrl key). You should find that you are able to rotate around

the sphere (you can tell that you are moving because the lighting changes).

Keep in mind that you are moving a camera around the object. When you zoom and rotate you are moving the camera,

not the object.

4 Stopping the program

Click “Edit this program” to return to editing. If you ran your program in a separate window by pressing Ctrl-2, you

can kill that window by clicking the window’s close box, or you can just leave it open while you edit your program,

and when you again press Ctrl-2 the new version will run in that window. GlowScript automatically saves your

program as you make changes in it.

5 A ball in a box

The goal of the following activity is to give you experience in using the velocity to update the position of an object, to

create a 3D animation. You will write a program to make a ball bounce around in a box, in 3D.

To position objects in the display window we use their 3D coordinates. The origin of the coordinate system is at the

center of the display window. The positive

x

axis runs to the right, the positive

y

axis runs up, and the positive

z

axis

comes out of th