Tuesday, March 31, 2015

Introduction to 3D Modeling with Vpython Lab

The purpose of this lab was to gain knowledge of how to properly use the Vpython 3D modeling program.

Pictured below is the result of my attempts to solve the first challenge, which involved creating 3 spheres with an arrow pointing out of each one in a specific direction.



Below is the code I used to create this picture:

from __future__ import division
from visual import *

sphere(pos = vector(0,0.5,0), radius = 0.2, color = color.blue)
sphere(pos = vector(0,-0.5,0), radius = 0.2, color = color.cyan)
sphere(pos = vector(-1,0,0), radius = 0.2, color = color.white)
arrow(pos = vector (0,0.5,0), axis = vector (-0.5,0,0), color = color.blue)
arrow(pos = vector (0,-0.5,0), axis = vector (0.5,0.5,0), color = color.cyan)
arrow(pos = vector (-1,0,0), axis = vector (0,-0.5,0), color = color.white)

The following is my attempt to solve the second challenge, which tasked me to create interlocking arrows between the 3 spheres going in a counterclockwise direction.



The code I used for this part of the lab is shown below:

from __future__ import division
from visual import *

Jack=sphere(pos = vector(0,0.5,0), radius = 0.2, color = color.blue)
Crack=sphere(pos = vector(0,-0.5,0), radius = 0.2, color = color.cyan)
Cadillac=sphere(pos = vector(-1,0,0), radius = 0.2, color = color.white)


arrow(pos = vector (0,0.5,0), axis = Cadillac.pos-Jack.pos, color = color.blue)
arrow(pos = vector (0,-0.5,0), axis = Jack.pos-Crack.pos, color = color.cyan)
arrow(pos = vector (-1,0,0), axis = Crack.pos-Cadillac.pos, color = color.white)



print(Jack.pos)

No comments:

Post a Comment