Project I: Matrices, Vectors, and Multiplication of them.

Your Project must be able to do the following:

You will be responsible for this project in groups of two people. You must comment all your code effectively so that I can follow what you are doing in them.

Points: 100

Due Date: January 27, 1998.


Since in this project one, I am going to help you get started. You will get less help on your other projects.

First, let’s design some classes:

 

class Point3D{

public:

Point3D();
Point3D(double xValue, double yValue, double zValue);
Point3D(Point3D &pt);
~Point3D();

double x;
double y;
double z;

};

class Vector{

public:

Vector();
Vector(double a, double b, double c, double d);
Vector(Vector &vector);
Vector(Point3D &pt); // create v={x,y,z,1}
~Vector();

double v[4];

};

class Matrix{

public:

Matrix();
Matrix(double a, double b, double c, double d,

double e, double f, double g, double h,
double i, double j, double k, double l,
double m, double n, double o, double p);

Matrix(Matrix &mat);
~Matrix();

double matrix[4][4];

};

 

This is a good start for all the classes. Begin by implementing these structures before continuing.

Now, that you have that done, lets do the input and output. Well, for input you can get read the input with cin and store the values, since they are public values. To output, let’s design a Print routine for each class:

void Print(fstream &file);

or we can overload the << operator for stream output by adding this to the class:

friend ostream& operator<< ( ostream& os, Point3D &pt );

and then the function would be(outside of the class):

ostream& operator<< ( ostream& os, Point3D &pt ){

os << "(" << pt.x << "," << pt.y << "," << pt.z << ")";

return os;

}

Do one or the either for each of the classes. Be sure not to output a newline with the print statements!

For the Point3D class we are done.

For Vector, we need to add:

Vector * Add(Vector &vec);

Which adds this to vec and returns the result when you cann Add.

We also need a subtract function, done the same way, but does this vec.

We also need the following functions:

void Normalize(void); //normalize this = this/||this||

//You should ignore the v[3]’s value!

double DotProduct(Vector &vec); //this· vec

Vector * CrossProduct(Vector &vec); //this x vec

For the Matrix class you will need:

Matrix * MultiplyM(Matrix &mat); //computes this * mat

Vector * MultiplyV(Vector &vec); // computes this * vec

 

Ok, here is what the main program should do:

  1. Ask the user to input a point, a vector, and a matrix, then output them to the screen.
  2. Enter a second matrix and multiply it by the first matrix and print the result.
  3. Multiply the vector times the second matrix.
  4. Ask the user for a second vector and compute the dot and cross products of the two matrices, and print the results.
  5. Ask the user for thee points on a plane. Compute the equation for the plane, storing the information A, B, C, and D in a vector. Print the equation to the screen.
  6. Ask the user for another point and compute whether or not the point is on the plane. Remember, you are using floating point numbers, so don’t just check for 0, check for less than an error bound!