So I'm convinced that my current teachers really shouldn't be teaching the class that I'm in because I really don't understand this lab and it's due on Wednesday the 8th.

If I could just have some suggestions on exactly what I supposed to do to get this program going. Doesn't have to be much maybe just an explanation on what this calls for.

Here's what the assignment says:

**Learning Objectives**

Create a C++ class that defines a vector object in homogeneous coordinates, and provides functions which determine angles associated with that vector.

Introduction

Vectors are a convenient and concise way of representing both location and motion in either 2D or 3D space. The attributes of a vector, and operations performed on vectors, are basic computational necessities. For this reason, a vector class that provides this information will be extremely useful. In this lab, you shall write a C++ class to work with vectors, and in future labs you will extend the functions of this class.

Separate classes for 2D and 3D vectors are not necessary. The xy-plane is already embedded in the 3D space, and this plane is simply a copy of the 2D space. Therefore, to represent a 2D vector in a 3D space, it is sufficient to set the third coordinate of the 3D space, z, equal to zero. (This will shorten our work for class, but may not always be the preferred solution in an actual game.)

It is actually easier to work with 3D vectors that have four components instead of three. Certainly this is not obvious now, but later it will allow us to represent translations of objects using matrix multiplication. When 4D vectors are used for 3D space, the coordinates are called homogeneous coordinates. Our book introduces homogeneous coordinates in chapter 6, but without specifying the name of the system. We shall refer to the fourth coordinate as the w-coordinate, and its value will always be equal to one.

There are many different formulas that relate vectors to angles. In three dimensions, they include angles made with each of the three axes, conversions from rectangular to Magnitude-Heading-Pitch, and vice versa. Specifically, the 3D formulas are:

cosα=vx∥v∥

cosβ=vy∥v∥

cosγ=vz∥v∥

vx=∥v∥cosPcosH

vy=∥v∥cosPsinH

vz=∥v∥sinP

∥v∥=v2x+v2y+v2z−−−−−−−−−−√

sinP=vz∥v∥

cosH=vxv2x+v2y−−−−−−√

The 2D formulas are actually special cases of these 3D formulas.

In this lab, you will create a C++ class that will define vectors and perform some simple vector computations, and any C++ program may call upon the services of this class. Since C++ already has a class called ‘vector’ in the Standard Template Library (whose purpose is not mathematical), you need to use a different name for your class (vector3D, for example). Usually the class would be its own file, but in order for us to ease into the concept of classes we will start off by having the class defined within our program.

The Vector3D Class

Your Vector3D class should have the following functions

Publicly

A constructor Vector3D. When the constructor is called it should set default values of <0,0,0,1> for the vector.

Two functions called SetRectGivenRect that will set the rectangular coordinates for the vector given an input of rectangular coordinates. One for 2D and one for 3D.

A function called setRectGivenPolar that will set the rectangular coordinates given the magnitude and heading (2D case)

A function called setRectGivenMagHeadPitch that will set the rectangular coordinates for the vector given an input of the magnitude, heading and pitch.(3D case)

A function called printRect that prints the rectangular coordinates to the screen.

A function called printMagHeadPitch that prints the magnitude, heading and pitch to the screen.

A function called printAngles that prints the angles alpha, beta and gamma that the vector makes with the three positive axes.

A function called getMagnitude that returns the magnitude of the vector.

A function called getPitch that returns the pitch of the vector.

A function called getHeading that returns the heading of the vector.

A function called getAlpha that returns the angle alpha

A function called getBeta that returns the angle beta

A function called getGamma that returns the angle gamma.

A function called getX that returns the x-coordinate.

A function called getY that returns the y-coordinate.

A function called getZ that returns the z-coordinate.

Privately

You should store the rectangular coordinates of the vector private to the class.

Defining the Vector3D Class

The class should be defined before your main. The syntax is as follows

Class Vector3D

class Vector3D { Public: return_type Vector3D(input_type) \\Constructor for the class Vector3D { \\The code here is executed every time a Vector3D is created } return_type FunctionName(input_type) \\Public Function for the class Vector3D { \\The code here is executed every time this function is called } Private: variable_type variableName \\Private Variable Declaration return_type FunctionName(input_type) \\Private Function for the class Vector3D { \\The code here is executed every time the function is called. \\This function can only be called from inside the class } };

Prelab Questions and Exercises

What will be the 4D homogeneous coordinates of the 3D vector (x, y, z)? Also, what will be the 4D homogeneous coordinates of the 2D vector (x, y)?

What formulas will be needed for the 4 set functions that Vector3D will have?

What modifications are needed so that your class can also handle the instantiation of 2D vectors?

Four of the nine formulas given in the introduction explicitly define the quantity (the formula is already solved for the particular variable of interest). These formulas are easy to implement. But the other formulas are written in terms of a trig function of an angle. Identify any cases that need to be addressed when solving for the angle in each formula.

Some of the formulas may need a degree-radian conversion, or vice versa. Explain how you plan to implement this conversion.

Laboratory Procedures

1. Create a C++ program that asks the user to enter a vector (either 2D or 3D) in rectangular components, calls upon the C++ class for its computations, then outputs using printRect, printMagHeadPitch, and printAngles.

2. Create a second C++ program that asks the user to enter a vector described by its magnitude, heading and pitch and then calls upon the C++ class for its computations, , then outputs using printRect, printMagHeadPitch, and printAngles.

(Do NOT combine this program with the previous program. These should be separate programs)

Since we are defining the class in the program, you can just cut and paste your code for the Vector3D class from the first program into the second program

3. Execute each of the two programs above, for your instructor’s verification. (Both programs should be ready to demonstrate at the same time, so it is clear that they are calling on the same class – and no changes were made in the interim.)

a. program in #2: initials _

b. program in #3: initials _

4. Save your class files! You will use them again in future labs (including the very next lab).

As I said my teachers have been no help at all, mostly due to the fact that they are teaching a programming class but neither of them have any programming experience.

This post has been edited by **jimblumberg**: 05 February 2012 - 04:28 PM

Reason for edit:: Added missing Code Tags, Please learn to use them.