# Learning Objectives

Extend your vector3D class to handle angle representations and add new operations on vectors.

# Introduction

In the previous experiment, you created a vector class to represent 3D vectors using 4D homogeneous coordinates and provided the class with a few functions for input and output as well as overloading operators for basic vector operations. In this experiment, we will extend the class by adding representations involving angles and adding some advanced vector operations

Specifically, we want to include the following functions:

- setRectGivenPolar - Allows a vector to be defined given a magnitude and angle
- setRectGivenMagHeadPitch - Allows a vector to be defined given a magnitude, heading, and pitch.
- printPolar - Outputs to the screen the magnitude and angle of the vector in an easily readable form
- printMagHeadPitch - Outputs to the screen the magnitude, heading, and pitch of the vector in an easily readable form
- printDirection - Outputs to the screen the Direction angles of the vector in an easily readable form
- getPitch - Returns the pitch of the vector
- getHeading - Returns the heading of the vector
- getAlpha - Returns the direction angle, alpha
- getBeta - Returns the direction angle, beta
- getGamma - Returns the direction angle, gamma

Specifically, we want to include the following operations:

- dot product of two vectors
- angle between two vectors
- the perpendicular projection of one vector onto another
- the parallel projection of one vector onto another

# Preparatory Thoughts

- What formulas will be needed to implement the new operations? List them.
- What cautions must be taken when dealing with user input in degrees?
- What cautions must be taken when using inverse trig functions to solve for angles?
- Work the following as a test case for your code.
- A bee begins its travels at the base of a 10.4-m utility pole that is leaning at a pitch of 85° at a heading of 319°. The bee travels 12.3 m at heading 124° and pitch 22°, then changes direction and travels 8.7 m at heading 55° and pitch 19°. Determine the distance, heading, and pitch of its current location as measured from the base of the utility pole.
- Determine the closest point on the utility pole to the bee by projecting the bee’s final position onto the pole (or, if necessary, a virtual extension of the pole).
- Determine the vector that would run from the bee to that closest point on the pole.
- Determine the distance and the unit direction of flight needed for the bee to fly directly from its final location to the top of the utility pole.
- Determine the direction angles of the pole.

# Laboratory Procedures

1. Extend your 3D vector class to include the functions and operations listed in the introduction.

2. Create a program that follows the motions of a bee. The motions will be described as three legs of the bee’s trip. Each leg has a previous location and a new location. The original location will be the origin and is the previous location only for the first leg. Specifically, the program should do the following steps:

- asks the user to enter angular information about leaning utility pole
- asks the user to enter a leg of a trip, in terms of distance, heading, and pitch
- performs the requested motion, starting from the previous location
- reports the distance, heading, and pitch of the new location from the original location
- reports the closest point on the pole to the bee
- reports the vector that runs from the bee to the closest point on the pole
- ask the user to continue or not
- repeats (as needed) the above steps to obtain all the legs of the bee’s motion
- reports the distance and unit direction vector needed for the bee to fly directly from its final location to the top of the utility pole
- reports the direction angles of the pole

4. Test your code with the two legs described in the prelab questions.

5. Execute the above program, for your instructor’s verification. (Your instructor will provide new information about three legs at the time of execution.)

initials:

6. Save your class files! We will use them again in future labs.

# Postlab Questions

1. In this lab, we did not check to see if our closest point was beyond the end of the pole. If it was, we just reported the point on a theoretical extension of the pole. In reality, what would the closest point be? Explain how you could check for this situation?

2. In this lab, we did not check to see if the bee had hit the ground. How could we check for this? What might we report as the bee's new location in this case?