Tuesday, 14 October 2008

Week 2

This week we we're asked to modify an incomplete program that would enable the user to add, subtract, multiply, divide and find the dot and cross product of given vectors. This was a bit more trickier then the previous weeks work but by using different texts as reading resources it became easier.



Here is some examples of the code:



To add


float totalX = _x + rhs._x;
float totalY = _y + rhs._y;
float totalZ = _z + rhs._z;
Vector VectorTotal (totalX, totalY, totalZ);



To multiply by a scalar


float totalX = _x * scalar;
float totalY = _y * scalar;
float totalZ = _z * scalar;

Vector VectorTotal (totalX, totalY, totalZ)

To find the Cross Product


float x1 = _x;
float y1 = _y;
float z1 = _z;
Vector vCrossProduct;
vCrossProduct._x = _y * v._z - _z *v._y;
vCrossProduct._y = _z * v._x - _x *v._z;
vCrossProduct._z = _x * v._y - _y *v._x;

There wasn't too many problems with this, just minor errors such as a missing semi-colon or missing out an underscore.

No comments: