Vector Angles
spacecraft-free-content-clip-art-vector-spaceship-thumbnail.jpg

Learning Objectives

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

Introduction

Previously, 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. You will then test them and apply them to a game scenario.

Specifically, we want to include the following methods to our Vector3D class:

  • setRectGivenPolar - Takes the vector's heading (in degrees) and magnitude as inputs and sets the vector's private x and y components
  • setRectGivenMagHeadPitch - Takes the vectors magnitude, heading (in degrees), and pitch (in degrees) as inputs and sets the vector's private x, y, and z components
  • printPolar - Outputs to the screen the magnitude and angle (in degrees) 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 vector's direction angles alpha, beta, and gamma in degrees in an easily readable form
  • getMag - returns the magnitude of the vector
  • 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 - takes in two Vector3D and returns the dot product
  • angle between two vectors - takes in two Vector3D and returns the angle in between in radians

Preparatory Thoughts

  1. What formulas will be needed to implement the new operations? List them.
  2. What cautions must be taken when dealing with user input in degrees?
  3. 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 methods and operations listed in the introduction.

2. In a 3D space race game, there are speed boost gates along the way. Each gate is a rectangle with some given normal vector. The more the ship is aligned with the gate when it passes through the more speed boost the ship is given. That is to say, the more the velocity vector of the ship agrees with the normal of the gate the more the boost the ship receives. 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 test your new methods and operations as well as 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 the magnitude, heading, and pitch of the space ship's velocity
  • asks the user to enter the 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 in degrees
  • 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. Give an example of two unequal vectors that would have the same direction angles.
  2. Explain what would need to be done to adjust the amount of speed boost a gate imparts on a ship.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License