To reverse the direction of an arrow without changing

This preview shows page 5 - 8 out of 11 pages.

-To reverse the direction of an arrow without changing its length, what scalar factor would you multiply axis by? Write this line of code on your whiteboard for the above example. 5
Image of page 5

Subscribe to view the full document.

3.11 Comment lines (lines ignored by the computer) Comment lines start with a # (pound sign). A comment line can be a note to yourself, such as: # objects created in following lines Or a comment can be used to remove a line of code temporarily, without erasing it. Put a # at the beginning of the line creating your arrow, and run the program: #arrow(pos=vector(2,-3,0), axis=-0.5* vector(3,4,0), color=color.cyan) Note the pound sign at the beginning of the line. The pound sign lets VPython know that anything after it is just a comment, not actual instructions. The statement will be skipped when the program is run. Run the program. Explain what you see on your whiteboard. 3.12 Representing position vectors with arrows Clean up your program so it contains only the following objects: A red sphere (representing a baseball) at location (− 5 , 2 , 3 ) , with radius 0.4 A green sphere (representing a tennis ball) at location (− 3 , 1 , 0 ) > , with radius 0.15 A cyan arrow with its tail at ( 2 , 3 , 0 ) and its tip at ( 2 , 3 , 0 ) + ( 3 , 4 , 0 ) We can use arrows to represent position vectors and relative position vectors. Remember that a relative position vector that starts at a position vector A and ends at a position vector B can be found by “final minus initial”, or vector B vector A . We want to make an arrow represent the relative position vector of the tennis ball with respect to the baseball. That is, the arrows tail should be at the position of the baseball (the red sphere), and the tip should be at the position of the tennis ball (the green sphere). Answer these questions on your whiteboard. Questions: -What would be the pos of this arrow, whose tail is on the baseball (the red sphere)? -What would be the axis of this arrow, so that the tip is on the tennis ball (the green sphere)? Write the line of code out on your whiteboard. Using these values of pos and axis , change the last line of the program to make the cyan arrow point from the red baseball to the green tennis ball. Run the program. Checkpoint : Examine the 3D display carefully. Change the location of the red baseball to ( 3 , 4 , 5 ) . What happens to the arrow? Return the baseball to (− 5 , 2 , 3 ) . 6
Image of page 6
3.13 Naming objects; Using object names and attributes We want this arrow to always point toward the tennis ball, no matter what position we give the tennis ball. To do this, we will have to refer to the tennis ball’s position symbolically . But first, because there is more than one sphere and we need to tell them apart, we need to give the objects names. Give names to the spheres by changing the “sphere” statements in the program to the fol- lowing: baseball = sphere(pos=vector(-5, 2, -3), radius=0.40, color=color.red) tennisball = sphere(pos=vector(-3,-1,0), radius=0.15, color=color.green) We’ve now given names to the spheres. We can use these names later in the program to re- fer to each sphere individually. Furthermore, we can specifically refer to the attributes of each object by writing, for example, tennisball.pos to refer to the tennis ball’s position attribute, or baseball.color to refer to the baseball’s color attribute. To see how this works, do the following exercise.
Image of page 7

Subscribe to view the full document.

Image of page 8
You've reached the end of this preview.
  • Spring '10
  • Jarrio
  • Physics, vpython, tennis ball

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern