Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

OBJECTIVES In this activity you will learn how to:Create3D box objectsUpdate the position of an object iteratively (repeatedly) to animate its motionUpdate the momentum and

OBJECTIVES

In this activity you will learn how to:Create3D box objectsUpdate the position of an object iteratively (repeatedly) to animate its motionUpdate the momentum and position of an object iteratively (repeatedly) to predict its motion

a.Creating objects

step 1.

We use a white box to represent the track. Type the following command and run the program.track = box(pos=vector(0,-.05, 0), size=vector (2.0, 0.05, .10), color=color.white) .We will now use a red box whose center is at the origin to represent a moving cart located at the origin. Type the following command and run the program.cart=box(pos=vector(0,0,0), size=vector(0.1, 0.05, 0.06), color=color.red)

step 2. Reposition the cart so its left end is aligned with the left end of the track. Run the program and make are sure it is working.

step 3. To model the motion of an object over time, we need to know the value of two vectors:initial position; andinitial velocity. You have already given the cart an initial position. Now you need to give it an initial velocity, velcart. If you push the cart with your hand, the initial velocity is the velocity of the cart just after it leaves your hand.

Give the cart a velocity of 0.5 m/s in the +x direction by adding the following commandvelcart= vector(0.50,0,0)#sets the carts velocity at 0.5 m/s in the +x direction

step 4. The objects velocity a short time, , later can be determined using the objects initial velocity and initial acceleration using the equation:=+

Looking at this equation, you probably notice that we will only be able to solve it if are told how the acceleration changes with time. One case where this is occurs is when the acceleration is constant. Later in the course, we will cover the general method for obtaining the acceleration of an object-based upon the forces acting upon an object which is called Newtons 2ndLaw.

step 5. Let us assume that our cart has constant velocity so our acceleration is zero. Add the following command to your program: accelcart= vector(0,0,0) #carts acceleration is set to zero.

We now set the initial time to zero, and set our step size, i.e. , to 0.01. Add the following commands and run your program.

t = 0 #initial time is 0

delta = 0.01 # time step size

step 6. In a computer program, a sequence of instructions that are to be repeated is called a loop. The kind of loop we will use in VPython starts with a "while" statement. Instructions inside the loop are indented. Glowscript will indent automatically after you type a colon. As an example of a loop, enter the following commands and run the program.

while t < 0.2:print (The time is now, t)

t = t + delta

print (after the loop)

The statement:t = t + delta may look like a mathematical error. However, in a program, the "=" sign has a different meaning than it does in a mathematical equation. The right hand side of the statement tells Python to read the old value of t, and add the value of delta to it. The left-hand side of the statement tells Python to store this new value into the variable t.

step 7. Constant velocity

We now want to model the constant velocity cart iteratively using a loop. Modify the loop in your program to make it look like the following and run your program:

whilet < 2:print("time = ", t, " position = ", cart.pos, " velocity = ",velcart)

cart.pos=cart.pos+ velcart*deltat #computes new position

velcart = velcart + accelcart*deltat #computes new velocity

t = t + deltat

print(The End)

step 8. Modify the while statement in your program so that it runs just long enough for the cart to travel 2 meters.

step 9. Slowing down the animation

when you run the program, you should see the cart at its final point. The program is executed so rapidly that the entire motion occurs faster than we can see, because a "virtual time" in the program elapses much faster than real-time does. We can slow down the animation rate by adding a rate statement.

.Add the following line inside your loop (indented) and run the program: rate(100) Every time the computer executes the loop, when it reads rate(100), it pauses long enough to ensure the loop will take 1/100th of a second. Therefore, the computer will only execute the loop 100 times per second. You should see the cart travel to the right at a constant velocity, ending up 2 meters from its starting location.

step 10. Modify your code so that the cart starts at the right end of the track and moves to the left till it just reaches the end of the track.

I followed all those steps and my program did not work. Can you please show me how to correctly do this in glowscrpt.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions