# Connexions

You are here: Home » Content » GAME 2302-0370 Motion -- Uniform and Relative Velocity

### Recently Viewed

This feature requires Javascript to be enabled.

# GAME 2302-0370 Motion -- Uniform and Relative Velocity

Module by: R.G. (Dick) Baldwin. E-mail the author

Summary: The purpose of this module is to explain uniform velocity and relative velocity.

## Preface

### General

This module is part of a series of modules designed for teaching the physics component of GAME2302 Mathematical Applications for Game Development at Austin Community College in Austin, TX. (See GAME 2302-0100: Introduction for the first module in the course along with a description of the course, course resources, homework assignments, etc.)

The purpose of this module is to explain uniform velocity and relative velocity.

### Viewing tip

I recommend that you open another copy of this document in a separate browser window and use the following links to easily find and view the Images and Listings while you are reading about them.

#### Images

• Image 1 . Screen output for Listing #1.
• Image 2 . Vector diagram for the hockey puck.
• Image 3 . Screen output for Listing #2.
• Image 4 . Vector diagram for a man on a train.
• Image 5 . Screen output for Listing #3.
• Image 6 . Another vector diagram for a man on a train
• Image 7 . Screen output for Exercise #2 for a man on a train.
• Image 8 . Vector diagram for man on aircraft carrier.
• Image 9 . Screen output for Listing #4.

## General background information

What is velocity?

Velocity is the time rate of change of position . Since displacement is the change of position, velocity is also the rate of displacement . Since displacement is a vector quantity, velocity is also a vector quantity -- it has magnitude and direction.

An airplane may traverse 350 miles in a northeasterly direction in one hour. This statement describes a vector quantity (velocity) because it has both magnitude and direction.

The same airplane may traverse 350 miles in a southwesterly direction in one hour. This statement describes a different velocity. Even though the magnitude is the same in both cases, the direction is different. Hence, the velocity is different.

What is speed?

Speed is distance covered in a unit of time without reference to direction. Since there is no reference to direction, speed is a scalar quantity.

A car may traverse 60 miles in one hour. An airplane may traverse 350 miles in one hour. An excellent runner may traverse one mile in three minutes. All of these statements describe scalar quantities (speed) since there is no reference to direction.

A person in a seat on a Ferris wheel may travel around the axle in the center of the wheel at a constant rotational speed. However, that person's velocity is not constant. The velocity is continually changing because the direction of motion is continually changing.

Uniform velocity

Velocity is uniform when equal distances along a straight line are traversed in equal intervals of time. In this case

v = s/t

where

• v is uniform velocity
• s is the distance traveled (displacement)
• t is an interval of time

Because uniform velocity occurs along a straight line, the computations involving uniform velocity, distance, and time may not necessarily include the direction of that straight line. However, since both displacement and velocity are vector quantities, it is understood that the direction of velocity is the same as the direction of the displacement.

On the other hand, as you will see later, when combining two or more uniform velocities into a single resultant velocity, the directions of the different uniform velocities becomes extremely important.

Speed, distance, and time

Note also that this same equation can be applied to computations involving speed, distance, and time where

• v represents speed and not velocity
• s is the distance traveled (not necessarily in a straight line)
• t is an interval of time

Units of velocity

The units of velocity are units of distance (such as meters) divided by units of time (such as seconds).

## Discussion and sample code

### A simple exercise on uniform velocity

Let's begin this section with a short exercise involving uniform velocity.

How long does it take an airplane traveling at a uniform velocity of 350 miles per hour to traverse a distance of 700 miles?

Please copy the code shown in Listing 1 into an html file and open the file in your browser.

Figure 1: Listing 1: A simple exercise on uniform velocity.
Listing 1: A simple exercise on uniform velocity.
<!---------------- File JavaScript01.html --------------------->
<html><body>
<script language="JavaScript1.3">

document.write("Start Script" + "<br/>")

var velocity = 350;//uniform velocity in miles/hour
var distance = 700;//miles

var time = distance/velocity;//miles/(miles/hour) = hours

document.write("uniform velocity = " + velocity +
" miles/hour<br/>");
document.write("distance = " + distance + " miles<br/>");
document.write("time = " + time + " hours<br/>");
document.write("End Script")

</script>
</body></html>


Screen output

The text shown in Image 1 should appear in your browser window when you open the html file in your browser.

Figure 2: Image 1: Screen output for Listing #1.
Image 1: Screen output for Listing #1.
Start Script
speed = 350 miles/hour
distance = 700 miles
time = 2 hours
End Script 

Analysis of the code

The equation given earlier that shows the relationship among uniform velocity, distance, and time can be manipulated algebraically to find any one of the three terms when the values of the other two terms are known. The objective in this exercise is to find the time required to traverse a known distance with a known uniform velocity.

Algebraic manipulation of the equation

Multiplying both sides of the equation by t and dividing both sides by v allows us to rewrite the equation as

t = s/ v

where

• v is uniform velocity
• s is the distance traveled
• t is an interval of time

The solution to the problem is...

This version of the equation is used in Listing 1 to solve for the time required to traverse 700 miles at a uniform velocity of 350 miles/hour. The answer is 2 hours as shown in Image 1 .

Declare and initialize variables

The code in Listing 1 begins by declaring and initializing variables named velocity and distance . Note that the units are shown in the comments. I recommend that you always do that in order to keep the units straight.

Perform the arithmetic

Then Listing 1 declares a variable named time and sets its value equal to distance divided by velocity . Once again, note the treatment of the units in the comments, showing that the units for the result of the division are hours.

Display the results

Finally, Listing 1 calls the document.write method several times in succession to display the results shown in Image 1 .

### An exercise on average velocity

A hockey puck is struck by a player causing it to travel northeast at a uniform velocity of 50 feet per second for 15 feet, at which point it is struck by another player.

When struck by the second player, the direction of motion is changed to northwest with a uniform velocity of 60 feet per second.

It is stopped by a third player after traveling 20 feet in the northwest direction.

• What is the time required for the puck to complete each leg of its journey?
• What is the average velocity of the puck from the start to the end of its journey?

Vector diagram for the hockey puck

Image 2 shows a vector diagram for the hockey puck.

Let's write a script to solve the problem

Please copy the code from Listing 2 into an html file and open it in your browser.

Figure 4: Listing 2: An exercise on average velocity.
Listing 2: An exercise on average velocity.
<!---------------- File JavaScript02.html --------------------->
<html><body>
<script language="JavaScript1.3">

document.write("Start Script <br/>");

// and opposite side values for a right triangle and to
// return the angle in degrees in the correct quadrant.
function getAngle(x,y){
if((x == 0) && (y == 0)){
//Angle is indeterminate. Just return zero.
return 0;
}else if((x == 0) && (y > 0)){
//Avoid divide by zero denominator.
return 90;
}else if((x == 0) && (y < 0)){
//Avoid divide by zero denominator.
return -90;
}else if((x < 0) && (y >= 0)){
return Math.atan(y/x)*180/Math.PI + 180;
}else if((x < 0) && (y <= 0)){
return Math.atan(y/x)*180/Math.PI + 180;
}else{
//First and fourth quadrants. No correction required.
return Math.atan(y/x)*180/Math.PI;
}//end else
}//end function getAngle

//Compute the time required to traverse each leg. Identify
// the two legs as A and B.
var vecAmag = 15;//displacement in feet
var vecAang = 45;//displacement angle in degrees
var vecAvel = 50;//velocity magnitude in feet per second
var timeA = vecAmag/vecAvel;//feet/(feet/second) = seconds

var vecBmag = 20;//displacement in feet
var vecBang = 135;//displacement angle in degrees
var vecBvel = 60;//velocity magnitude in feet per second
var timeB = vecBmag/vecBvel;//feet/(feet/second) = seconds

//Compute the overall displacement
//Compute the horizontal and vertical components
// of each vector.
var vecAh = vecAmag*Math.cos(vecAang*Math.PI/180);
var vecAv = vecAmag*Math.sin(vecAang*Math.PI/180);

var vecBh = vecBmag*Math.cos(vecBang*Math.PI/180);
var vecBv = vecBmag*Math.sin(vecBang*Math.PI/180);

//Compute the sums of the horizontal and vertical
// components from the two vectors to get the
// horizontal and vertical component  of the
// resultant vector.
var vecResultH = vecAh + vecBh;
var vecResultV = vecAv + vecBv;

//Use the Pythagorean theorem to compute the magnitude of the
// resultant vector in feet.
var vecResultMag = Math.sqrt(Math.pow(vecResultH,2) +
Math.pow(vecResultV,2));

//Compute the angle of the resultant vector in degrees.
vecResultAng = getAngle(vecResultH,vecResultV);

var totalTime = timeA + timeB;//seconds
var vecVelMag = vecResultMag/totalTime;//feet/second
var vecVelAng = vecResultAng;//degrees

document.write("Time for leg A = " + timeA.toFixed(2) +
" seconds<br/>");
document.write("Time for leg B = " + timeB.toFixed(2) +
" seconds<br/>");
document.write("Displacement magnitude = " +
vecResultMag.toFixed(2) + " feet<br/>");
document.write("Displacement angle = " +
vecResultAng.toFixed(2) + " degrees<br/>");
document.write("Total time = " + totalTime.toFixed(2) +
" seconds<br/>");
document.write("Average velocity magnitude = " +
vecVelMag.toFixed(2) + " feet/second<br/>");
document.write("Average velocity angle = " +
vecVelAng.toFixed(2) + " degrees<br/>");

document.write("End Script");

</script>
</body></html>

Screen output

The text shown in Image 3 should appear in your browser window when the html file is opened in your browser.

Figure 5: Image 3: Screen output for Listing #2.
Image 3: Screen output for Listing #2.
Start Script
Time for leg A = 0.30 seconds
Time for leg B = 0.33 seconds
Displacement magnitude = 25.00 feet
Displacement angle = 98.13 degrees
Total time = 0.63 seconds
Average velocity magnitude = 39.47 feet/second
Average velocity angle = 98.13 degrees
End Script 

Analysis of the code

In this exercise, the puck makes a journey across the ice consisting of two sequential legs in different directions with different magnitudes of velocity. Although each leg involves motion along a line, the total trip is not along a line.

The objective of the script is to

• Compute and display the time required to traverse each leg of the trip based on the given information.
• Compute and display the magnitude and the angle of the displacement from start to finish.
• Compute and display the time required to complete the entire trip, which is the sum of the times from both legs.
• Compute and display the magnitude of the average velocity as the magnitude of the displacement divided by the total time.
• Recognize that the angle of the average velocity is the same as the angle of the displacement.

The getAngle function

The code in Listing 2 begins with the getAngle function that we developed and used an earlier module. The purpose of the function is to receive the adjacent and opposite side values for a right triangle as parameters and to return the angle in degrees in the correct quadrant.

I explained this function in an earlier module and won't repeat that explanation in this module.

Compute the time for each leg

Following the definition of the getAngle function, Listing 2 computes the time required to traverse each leg of the trip. For variable naming purposes, the two legs are identified as A and B.

Variable names that end with "mag" contain vector magnitudes. Variable names that end with "ang" contain vector angles. Variable names that end with "vel" contain the magnitudes of straight-line, uniform velocities.

The time to complete each leg of the trip is computed by dividing the magnitude of the displacement vector for that leg by the magnitude of the straight-line velocity for that leg. The resulting times have units of seconds, and are saved in the variables named timeA and timeB .

The overall displacement

The magnitude and angle of the overall displacement for the two-leg trip (identified by the variables named vecResultMag and vecResultAng respectively) are computed using procedures that were explained in an earlier module. Therefore, I won't repeat that explanation in this module.

The magnitude of the overall displacement is stored in the variable named vecResultMag , and the angle for the overall displacement is stored in the variable named vecResultAng .

The total time

The total time for the trip, identified by the variable named totalTime , is computed as the sum of the times for the individual legs.

Magnitude of the average velocity vector

The magnitude of the average velocity vector, identified by the variable named vecVelMag , is compute by dividing the magnitude of the displacement vector by the total time. This results in a value having units of feet/second as shown by the comments.

The direction of the average velocity vector

The direction of the average velocity vector, identified by the variable named vecVelAng , is recognized as being the same as the direction of the overall displacement vector with units of degrees.

Display the results

Finally, the document.write method is called several times in succession to display the output text shown in Image 3 .

### Multiple concurrent velocities

When a body has multiple concurrent velocities, the overall velocity of the body is equal to the vector sum of the individual velocities. You can compute that vector sum in any way that works for you, including the parallelogram rule, a tail-to-head vector diagram, or the mathematical techniques that we will use here.

Relative velocity

In this section, we will also be dealing with a topic called relative velocity . For example, suppose we see a man walking down the aisle in a passenger car of a train that is moving slowly at a uniform velocity along a straight track. How fast is the man moving?

The frame of reference

The answer to that question depends on the frame of reference of the observer. For example, to another passenger in the same rail car, it may appear that the man is moving at about 3 feet per second, which is a reasonably comfortable walking speed.

However, to someone standing on the ground outside of the passenger car (pretend that the side of the car is transparent), it may appear that the man is moving much faster or much slower than 3 feet per second, depending on which direction the man is moving relative to the motion of the train.

It could even turn out that insofar as the outside observer is concerned, the man isn't moving at all, or is moving backwards.

#### Exercise #1 for a man on a train

A man is walking along the aisle in a passenger car of a train that is moving at 1 mile per hour toward the east. The man is walking in the same direction that the train is moving. The man is walking at a uniform velocity of 2.933 feet per second. (You will see shortly why I chose such a strange walking speed for the man.) What is the man's overall velocity with reference to the ground?

Image 4 shows a vector diagram for the man on the train. The units for both velocity vectors must be the same. Therefore, the length of the velocity vector for the man is based on a conversion from 2.933 feet per second to 2 miles per hour.

JavaScript code

Please copy the code shown in Listing 3 into an html file and open the file in your browser.

Figure 7: Listing 3: Exercise #1 for a man on a train.
Listing 3: Exercise #1 for a man on a train.
<!---------------- File JavaScript03.html --------------------->
<html><body>
<script language="JavaScript1.3">

document.write("Start Script <br/>");

// and opposite side values for a right triangle and to
// return the angle in degrees in the correct quadrant.
function getAngle(x,y){

if((x == 0) && (y == 0)){
//Angle is indeterminate. Just return zero.
return 0;
}else if((x == 0) && (y > 0)){
//Avoid divide by zero denominator.
return 90;
}else if((x == 0) && (y < 0)){
//Avoid divide by zero denominator.
return -90;
}else if((x < 0) && (y >= 0)){
return Math.atan(y/x)*180/Math.PI + 180;
}else if((x < 0) && (y <= 0)){
return Math.atan(y/x)*180/Math.PI + 180;
}else{
//First and fourth quadrants. No correction required.
return Math.atan(y/x)*180/Math.PI;
}//end else
}//end function getAngle
//------------------------------------------------------------//

//The purpose of this function is to add two vectors, given
// the magnitude and angle (in degrees) for each vector.
// The magnitude and angle (in degrees) of the resultant
// vector is returned in a two-element array, with the
// magnitude in the element at index 0 and the angle in the
// element at index 1. Note that this function calls the
// getAngle function, which must also be provided in the
// script. To use this function to subtract one vector from
// another, add 180 degrees to the angle for the subtrahend
// vector before passing the angle to the function. To use
// this function to add more than two vectors, add the first
// two vectors as normal, then add the output from this
// function to the third vector, etc., until all of the
// vectors have been included in the sum.
function vectorSum(vecAmag,vecAang,vecBmag,vecBang){
var vecResult = new Array(2);
//Compute the horizontal and vertical components
// of each vector.
var vecAh = vecAmag*Math.cos(vecAang*Math.PI/180);
var vecAv = vecAmag*Math.sin(vecAang*Math.PI/180);

var vecBh = vecBmag*Math.cos(vecBang*Math.PI/180);
var vecBv = vecBmag*Math.sin(vecBang*Math.PI/180);

//Compute the sums of the horizontal and vertical
// components from the two vectors to get the
// horizontal and vertical component  of the
// resultant vector.
var vecResultH = vecAh + vecBh;
var vecResultV = vecAv + vecBv;

//Use the Pythagorean theorem to compute the magnitude of
// the resultant vector.
vecResult[0] = Math.sqrt(Math.pow(vecResultH,2) +
Math.pow(vecResultV,2));

//Compute the angle of the resultant vector in degrees.
vecResult[1] = getAngle(vecResultH,vecResultV);

return vecResult;
}//end vectorSum function
//------------------------------------------------------------//

//The main script body begins here.

//Establish the magnitude and angle for each vector.
var vecTrainMag = 1;//magnitude of velocity of train in miles/hr
var vecTrainAng = 0;//angle of velocity of train in degrees

var vecManMag = 2.933*3600*(1/5280);//Magnitude of velocity of
// man (ft/sec)*(sec/hr)*(mile/ft)
// = miles/hour
var vecManAng = 0;//angle of velocity of man in degrees

var resultant = vectorSum(vecTrainMag,vecTrainAng,
vecManMag,vecManAng);

//Display the magnitude and direction of the resultant vector.
document.write("Velocity magnitude = " +
resultant[0].toFixed(2) + " miles/hour<br/>");
document.write("Velocity angle = " +
resultant[1].toFixed(2) + " degrees<br/>");

document.write("End Script");

</script>
</body></html>



Screen output

The text shown in Image 5 should appear in your browser window when you open the html file in your browser.

Figure 8: Image 5: Screen output for Listing #3.
Image 5: Screen output for Listing #3.
Start Script
Velocity magnitude = 3.00 miles/hour
Velocity angle = 0.00 degrees
End Script  

Analysis of the code

As before, the script begins by defining the getAngle function, which doesn't require further explanation.

The vectorSum function

As you can see from Listing 3 , this script contains a new function named vectorSum . The purpose of this function is to add two vectors, given the magnitude and angle (in degrees) for each vector as incoming parameters. (The function assumes that both incoming magnitude parameters are expressed in the same units.)

The need to add two vectors occurs so often in physics that I decided to encapsulate the capability into a function that we can copy into future scripts. That will relieve us of the need to rewrite the code each time we need that functionality.

Return an array object

The magnitude and the angle (in degrees) of the resultant vector is returned in a two-element array object, with the magnitude in the element at index 0 and the angle in the element at index 1. I will have a more to say about arrays shortly.

Note that this function calls the getAngle function, which must also be provided in the script.

Subtraction of vectors

The function can also be used to subtract one vector from another. To subtract one vector from another, simply add 180 degrees to the angle for the subtrahend vector before passing the angle to the function.

Although the function can only be used to add two vectors, it can be called repeatedly to add any number of vectors two at a time.

To use this function to add more than two vectors, add the first two vectors as normal. Then add the vector output from the function to the third vector, etc., until all of the vectors have been included in the sum.

The code in the vectorSum function

Most of the code in the function is the same as code that I have explained in earlier modules. However, there are a couple of lines of code that are different.

The function begins with the following statement:

var vecResult = new Array(2);

The purpose of this statement is to create a two-element array object named vecResult .

What is an array object?

You can think of an array object as a software object containing pigeon holes into which you can store data and from which you can later retrieve that data. This particular array object has two pigeon holes, and they are numbered 0 and 1.

This array object will be used as a container to return the magnitude and angle values for the resultant vector.

Can only return one item

A JavaScript function can only return one item. Up to this point in these modules, that item has consisted of a single numeric value, such as the angle value that is returned from the getAngle function.

However, the vectorSum function needs to return two different values. One way to do that is to put those two values in the pigeon holes of an array object and return that array object as the one item that can be returned.

Store the resulting magnitude in the array object

Once the array object is created, the code in the function shown in Listing 3 is essentially the same as the code used earlier to add two vectors, down to the statement that begins with:

vecResult[0] = Math.sqrt(Math.pow(vecResultH,2) +...

That statement computes the magnitude of the resultant vector the same way as before, but instead of storing the value of the magnitude in a variable, it is stored in the first pigeon hole of the array object.

The value is directed into the first pigeon hole (technically called element) by the "[0]" that you see following the name of the array object in that statement.

Store the resulting angle in the array object

Immediately thereafter, the statement in Listing 3 that reads

vecResult[1] = getAngle(vecResultH,vecResultV);

computes the angle for the resultant vector and stores it in the second element in the array object (the element identified by the index value 1).

Return the array object for use later

These same index values along with the square brackets "[ ]" will be used later to retrieve the magnitude and angle values from the array object.

Finally, the function returns the array object to the calling script by executing the statement that reads

return vecResult;

The main script body

The main script body begins where indicated by the comment in Listing 3 .

The first four statements establish values for the magnitude and direction of the two vectors that represent the train and the man. There is nothing in those statements that you haven't seen before.

Note the treatment of the units

However, I encourage you to pay attention to the treatment of units in the comments for the value stored in the variable named vecManMag . The arithmetic in that statement uses two different conversion factors to convert the value from feet per second to miles per hour.

Once again, working through the units in this fashion can help you to organize your arithmetic correctly.

Call the vectorSum function

The statement that begins

var resultant = vectorSum(vecTrainMag...

calls the new vectorSum function to add the two vectors, passing the magnitude and angle for each vector as parameters.

Store the returned array object in a variable

This statement also declares a new variable named resultant . The array object that is returned from the vectorSum function is stored in this variable.

Once this statement finishes executing, the magnitude and angle of the resultant vector have been computed and saved for later use. (In this script, the only use of those two values is to display them later. However, they will be used in a more significant way in another exercise later.)

Code to display the results

The call to the vectorSum function is followed by three calls to the document.write method. The first two calls display magnitude and angle values, and the third call simply displays some text to indicate that the script has finished executing.

Displaying the magnitude value

If you examine the statement containing the first call to the document.write method, you will see that the argument list contains the following expression:

resultant[0].toFixed(2)

In this case, the "[0]" means to retrieve the value stored in the array element identified by the index value 0.

Once that value has been retrieved, the built-in toFixed method is called, passing the literal value 2 as a parameter, to format the value so that it will be displayed with two digits to the right of the decimal point.

Image 5 shows that value displayed in the line of text that reads:

Velocity magnitude = 3.00 miles/hour

(Note that very few of the values that I display in these modules comply with the rules for decimal digits and significant figures that I explained in an earlier module.)

A partial solution to the problem

A partial answer to the question posed for this exercise is that the magnitude of the man's overall velocity with respect to the ground is 3 miles per hour as shown in Image 5 .

The rest of the solution

The next statement in Listing 3 uses a similar syntax to retrieve the value from the second element in the array object (the element with an index value of 1) and to display it as

Velocity angle = 0.00 degrees

as shown in Image 5 .

This means that the man is moving due east (the same direction that the train is moving) with a velocity of 3 miles per hour with reference to the ground.

Analysis of the results

Now I will tell you why I used a strange walking speed (2.933 feet per second) for the man. As it turns out, this is very close to 2 miles per hour, and I wanted the man to have a walking speed that would result in simple numeric results.

Let's review the problem

The train is moving east with a uniform velocity of 1 mile per hour relative to the ground.

The man is moving east with a uniform velocity of 2 miles per hour (2.933 feet per second) relative to the train.

What is the man's velocity relative to the ground?

The algebraic sum of the magnitudes

Because the man and the train are both moving along the same straight line, and the man's velocity is stated relative to the train, the magnitude of the man's velocity relative to the ground is the algebraic sum of the magnitudes of the two velocities. Because they are both moving in the same direction, that algebraic sum is additive.

An analysis of the velocities

The train is moving 1 mile per hour with reference to the ground, and the man is moving 2 miles per hour with reference to the train (along the same line and in the same direction as the train). Therefore, the man is moving 1+2=3 miles per hour with reference to the ground.

This means that an observer standing on the ground at a point on a line perpendicular to the train would perceive the man to be moving to the to the right with a velocity of 3 miles per hour (assuming that the train is moving to the right).

A zero-degree angle is not required

Note that it isn't necessary that the train and the man be moving at an angle of zero degrees (east). The magnitude of the result would be the same regardless of the direction that they are moving provided they are moving along the same straight line.

We will specify a different common direction for the train and the man in the next exercise.

#### Exercise #2 for a man on a train

A man is walking in a passenger car of a train that is moving at 1 mile per hour toward the northeast (45 degrees). The man is walking in the opposite direction than the train is moving at 2.933 feet per second. (This means that the angle for the man's velocity vector is 225 degrees.)

What is the man's velocity with reference to the ground?

Another vector diagram for a man on a train

Image 6 shows another vector diagram for a man on a train. Once again, the units for both velocity vectors must be the same. Therefore, the length of the velocity vector for the man is based on a conversion from 2.933 feet per second to 2 miles per hour.

Make a new html file

Please copy the code from the previous exercise into a new html file, make the changes described below, and open the html file in your browser.

• Change the value of vecTrainAng from 0 to 45.
• Change the value of vecManAng from 0 to 225.

(Because of the small differences between this script and the previous script, I won't publish a copy of this new script here.)

Screen output

The text shown in Image 7 should appear in your browser window when you open the file in your browser.

Figure 10: Image 7: Screen output for Exercise #2 for a man on a train.
Image 7: Screen output for Exercise #2 for a man on a train.
Start Script
Velocity magnitude = 1.00 miles/hour
Velocity angle = 225.00 degrees
End Script 

Analysis of the results

The man and the train are still moving along the same straight line even though the angle is no longer 0. Therefore, the magnitudes of the two vectors still add algebraically. In this case, however, the man and the train are moving in opposite directions, so they are no longer additive.

The man has a greater velocity magnitude

The magnitude of the man's velocity in the direction of 225 degrees is greater than the magnitude of the train's velocity in the opposite direction of 45 degrees.

As you can see from Image 7 , the man's velocity with reference to the ground is 1 mile per hour at an angle of 225 degrees. This means that an observer standing on the ground at a point on a line perpendicular to the train would perceive the man to be moving to the left at 1 mile per hour (assuming that the train is moving to the right).

#### An exercise with three vectors in a plane

Now we are going to take a look at an exercise involving three vectors in a plane, which are not in a line.

An aircraft carrier is steaming east with a uniform velocity of 2 miles per hour relative to the ground beneath the ocean. A large platform on the deck is sliding northeast with a uniform velocity of 2 miles per hour relative to the ship. A man is walking north on the platform with a uniform velocity of 2 miles per hour relative to the platform.

What is the velocity of the platform with reference to the ground below the ocean?

What is the velocity of the man with reference to the ground below the ocean?

Vector diagram for man on aircraft carrier

Image 8 shows a vector diagram for the man on the aircraft carrier.

Create the script

Please copy the code from Listing 4 into an html file and open the html file in your browser.

Figure 12: Listing 4: An exercise with three vectors in a plane.
Listing 4: An exercise with three vectors in a plane.

<!---------------- File JavaScript04.html --------------------->
<html><body>
<script language="JavaScript1.3">

document.write("Start Script <br/>");

// and opposite side values for a right triangle and to
// return the angle in degrees in the correct quadrant.
function getAngle(x,y){

if((x == 0) && (y == 0)){
//Angle is indeterminate. Just return zero.
return 0;
}else if((x == 0) && (y > 0)){
//Avoid divide by zero denominator.
return 90;
}else if((x == 0) && (y < 0)){
//Avoid divide by zero denominator.
return -90;
}else if((x < 0) && (y >= 0)){
return Math.atan(y/x)*180/Math.PI + 180;
}else if((x < 0) && (y <= 0)){
return Math.atan(y/x)*180/Math.PI + 180;
}else{
//First and fourth quadrants. No correction required.
return Math.atan(y/x)*180/Math.PI;
}//end else
}//end function getAngle
//------------------------------------------------------------//

//The purpose of this function is to add two vectors, given
// the magnitude and angle (in degrees) for each vector.
// The magnitude and angle (in degrees) of the resultant
// vector is returned in a two-element array, with the
// magnitude in the element at index 0 and the angle in the
// element at index 1. Note that this function calls the
// getAngle function, which must also be provided in the
// script. To use this function to subtract one vector from
// another, add 180 degrees to the angle for the subtrahend
// vector before passing the angle to the function. To use
// this function to add more than two vectors, add the first
// two vectors as normal, then add the output from this
// function to the third vector, etc., until all of the
// vectors have been included in the sum.
function vectorSum(vecAmag,vecAang,vecBmag,vecBang){
var vecResult = new Array(2);
//Compute the horizontal and vertical components
// of each vector.
var vecAh = vecAmag*Math.cos(vecAang*Math.PI/180);
var vecAv = vecAmag*Math.sin(vecAang*Math.PI/180);

var vecBh = vecBmag*Math.cos(vecBang*Math.PI/180);
var vecBv = vecBmag*Math.sin(vecBang*Math.PI/180);

//Compute the sums of the horizontal and vertical
// components from the two vectors to get the
// horizontal and vertical component  of the
// resultant vector.
var vecResultH = vecAh + vecBh;
var vecResultV = vecAv + vecBv;

//Use the Pythagorean theorem to compute the magnitude of
// the resultant vector.
vecResult[0] = Math.sqrt(Math.pow(vecResultH,2) +
Math.pow(vecResultV,2));

//Compute the angle of the resultant vector in degrees.
vecResult[1] = getAngle(vecResultH,vecResultV);

return vecResult;
}//end vectorSum function
//------------------------------------------------------------//

//Main body of script begins here.

//Establish the magnitude and angle for each vector.
var vecShipMag = 2;//magnitude of velocity of ship in miles/hr
var vecShipAng = 0;//angle of velocity of ship in degrees

var vecPlatMag = 2;//magnitude of velocity of platform miles/hr
var vecPlatAng = 45;//angle of velocity of platform in degrees

var vecManMag = 2;//Magnitude of velocity of man in miles/hr
var vecManAng = 90;//angle of velocity of man in degrees

var platformVel =
vectorSum(vecShipMag,vecShipAng,vecPlatMag,vecPlatAng);
var manVel =
vectorSum(platformVel[0],platformVel[1],vecManMag,vecManAng);

//Display the magnitude and direction of the resultant vectors.
document.write("Platform velocity magnitude = " +
platformVel[0].toFixed(2) + " miles/hour<br/>");
document.write("Platform velocity angle = " +
platformVel[1].toFixed(2) + " degrees<br/>");
document.write("Man velocity magnitude = " +
manVel[0].toFixed(2) + " miles/hour<br/>");
document.write("Man velocity angle = " +
manVel[1].toFixed(2) + " degrees<br/>");

document.write("End Script");

</script>
</body></html>



Screen output

The text shown in Image 9 should appear in your browser window when the html file is opened in your browser.

Figure 13: Image 9: Screen output for Listing #4.
Image 9: Screen output for Listing #4.
Start Script
Platform velocity magnitude = 3.70 miles/hour
Platform velocity angle = 22.50 degrees
Man velocity magnitude = 4.83 miles/hour
Man velocity angle = 45.00 degrees
End Script 

Analysis of the code

The velocity of the platform relative to the ground is the vector sum of the ship's velocity and the velocity of the platform relative to the ship. The man's velocity is the vector sum of the platform's velocity relative to the ground and the man's velocity relative to the platform.

Listing 4 begins with copies of the getAngle function and the vectorSum function, which I have already explained. This discussion begins at the comment that reads "Main body of script begins here."

The main body of the script

The main body begins with the declaration and initialization of six variables whose contents represent the magnitude and the angle of the ship, the platform, and the man.

The vectorSum function is called to add the ship's velocity vector (relative to the ground) and the platform's velocity vector (relative to the ship). The resultant vector produced by adding those two vectors is stored in the array-object variable named platformVel for use later. This is the platform's velocity vector relative to the ground.

Add the man's vector to the sum

Then the vectorSum function is called again to add the platform's velocity vector (relative to the ground) and the man's velocity vector (relative to the platform). Note that the two values stored in the platformVel array object are extracted and passed as parameters to the vectorSum function.

The resultant vector produced by that addition is saved in the array-object variable named manVel . This is the man's velocity vector relative to the ground.

Display the results

Finally, the method named document.write is called four times in succession to extract and print the four values stored in the two array objects, producing the text output shown in Image 9 .

## Run the scripts

I encourage you to run the scripts that I have presented in this lesson to confirm that you get the same results. Copy the code for each script into a text file with an extension of html. Then open that file in your browser. Experiment with the code, making changes, and observing the results of your changes. Make certain that you can explain why your changes behave as they do.

## Miscellaneous

This section contains a variety of miscellaneous information.

### Note:

Housekeeping material
• Module name: GAME 2302-0370 Motion -- Uniform and Relative Velocity
• File: Game0370.htm
• Published: 10/13/12
• Revised: 12/31/12

### Note:

Disclaimers:

Financial : Although the Connexions site makes it possible for you to download a PDF file for this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should be aware that some of the HTML elements in this module may not translate well into PDF.

I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.

In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please be aware that it is a copy of a module that is freely available on cnx.org and that it was made and published without my prior knowledge.

Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.

-end-

## Content actions

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks