///This class is used to store information for a 3D vector. #include #include using namespace std; #ifndef RTSVECTOR3D_H #define RTSVECTOR3D_H template class vector3D { //friend class point3D; public: //data values T x; T y; T z; vector3D(); /// operator+(vector3D param); /// operator-(vector3D param); /// param); /// operator*(T param); /// X(vector3D param); /// operator*(const T lhs, vector3D rhs){return rhs*lhs;} /// Times(vector3D param); /// Normalize(); /// operator vector3D(); /// &rhs) { os<<"("< template vector3D::operator vector3D() { vector3D cast_result(x, y, z); return cast_result; } template vector3D::vector3D() { x=0; y=0; z=0; } template vector3D::vector3D(T new_x, T new_y, T new_z) { x=new_x; y=new_y; z=new_z; } template vector3D vector3D::operator -(vector3D param) { vector3D result; //create the result result.x = x-param.x; //perform the computation result.y = y-param.y; result.z = z-param.z; return result; } template vector3D vector3D::operator+(vector3D param) { vector3D result; //create the result result.x = x+param.x; //perform the computation result.y = y+param.y; result.z = z+param.z; return result; } template vector3D vector3D::Times(vector3D param) { vector3D result; //create the result result.x = x*param.x; //perform the computation result.y = y*param.y; result.z = z*param.z; return result; } template vector3D vector3D::operator*(T param) { vector3D result; //create the result result.x = x*param; //perform the computation result.y = y*param; result.z = z*param; return result; } template T vector3D::operator *(vector3D param) { //This function computes the dot product between two vectors return x*param.x + y*param.y + z*param.z; } template vector3D vector3D::X(vector3D param) { vector3D result; result.x=y*param.z - z*param.y; result.y=z*param.x - x*param.z; result.z=x*param.y - y*param.x; return result; } template vector3D vector3D::Normalize() { T length = Length(); if(length ==0.0) { x = y = z = 0; } else { x/= length; y /=length; z /=length; } return *this; } template T vector3D::Length() { return sqrt(x*x + y*y + z*z); } template void vector3D::print() { cout<<"["<