# 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

# 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?

# Laboratory Procedures

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

2. In a 3D space race game, there are speed boost gates along the way. The more the ship is aligned with the gate when it passes through the more speed boost that is given. Specifically, the new velocity of the space ship will be the same direction as the old velocity, but with magnitude equal to the dot product of the old velocity and the normal vector of the gate. Create a program that will compute the new velocity of a space ship after it passes through such a speed boost gate by writing code to do the following.

- asks the user to enter magnitude, heading, and pitch of the space ship's velocity
- asks the user to enter x, y, and z components of the speed boost gate's normal vector
- report the x, y, and z components of the space ship's velocity
- report the magnitude, heading, and pitch of the speed boost gate's normal vector
- reports the dot product of the two vectors
- report the angle between the two vectors
- reports the space ship's new velocity vector in Cartesian form
- reports the space ship's new velocity vector in MHP form
- reports the direction angles of the space ship's new velocity vector

# 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?