Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //217CR 1st Assignment
- //Brendan Smith
- //TVector Contructors and Functions
- //The Inports
- #include "TVector3D.h"
- #include <math.h>
- #include <iostream>
- using namespace std;
- // The Default constructor
- TVector3D::TVector3D(void)
- {
- _x=0;
- _y=0;
- _z=0;
- }
- // The Second constructor
- TVector3D::TVector3D(double vecx, double vecy, double vecz)
- {
- _x=vecx;
- _y=vecy;
- _z=vecz;
- }
- // Function that adds two 3D vectors together
- TVector3D TVector3D::AddVectors(TVector3D vector1, TVector3D vector2, TVector3D vector_result)
- {
- vector_result._x = vector1._x + vector2._x;
- vector_result._y = vector1._y + vector2._y;
- vector_result._z = vector1._z + vector2._z;
- cout<<"Addition: "<<vector_result._x<<" ,"<<vector_result._y<<" ,"<<vector_result._z;
- cout<<" \n";
- return vector_result;
- }
- // Function that subtracts two 3D vectors together
- TVector3D TVector3D::SubstractVectors(TVector3D vector1, TVector3D vector2, TVector3D vector_result)
- {
- vector_result._x = vector1._x - vector2._x;
- vector_result._y = vector1._y - vector2._y;
- vector_result._z = vector1._z - vector2._z;
- cout<<"Subtracts: "<<vector_result._x<<" ,"<<vector_result._y<<" ,"<<vector_result._z;
- cout<<" \n";
- return vector_result;
- }
- // Function that Crosses two 3D vectors together.
- TVector3D TVector3D::CrossVectors(TVector3D vector1, TVector3D vector2, TVector3D vector_result)
- {
- vector_result._x = (vector1._y * vector2._z) - (vector1._z * vector2._y);
- vector_result._y = (vector1._x * vector2._z) - (vector1._z * vector2._x);
- vector_result._z = (vector1._x * vector2._y) - (vector1._z * vector2._x);
- cout<<"Cross: "<<vector_result._x<<" ,"<<vector_result._y<<" ,"<<vector_result._z;
- cout<<" \n";
- return vector_result;
- }
- //Function that finds the Magnitude of a 3D vectors.
- double TVector3D::MagnitudeVectors(TVector3D vector1)
- {
- double result;
- result = sqrt((vector1._x * vector1._x) + (vector1._y * vector1._y) + (vector1._z * vector1._z));
- cout<<"Magnitude: "<<result;
- cout<<" \n";
- return result;
- }
- // Function that finds the Unit of a 3D vectors.
- TVector3D TVector3D::UnitVectors(TVector3D vector1, TVector3D vector_result)
- {
- double length = TVector3D::MagnitudeVectors(vector1);
- vector_result._x = vector1._x / length;
- vector_result._y = vector1._y / length;
- vector_result._z = vector1._z / length;
- cout<<"Unit: "<<vector_result._x<<" ,"<<vector_result._y<<" ,"<<vector_result._z;
- cout<<" \n";
- return vector_result;
- }
- // Function that Inverts a 3D vectors.
- TVector3D TVector3D::InvertVectors(TVector3D vector1, TVector3D vector_result)
- {
- vector_result._x = -vector1._x;
- vector_result._y = -vector1._y;
- vector_result._z = -vector1._z;
- cout<<"Invert: "<<vector_result._x<<" ,"<<vector_result._y<<" ,"<<vector_result._z;
- cout<<" \n";
- return vector_result;
- }
- // Function that finds the Dot Produc of two 3D vectors.
- double TVector3D::DotProductVectors(TVector3D vector1, TVector3D vector2, double result)
- {
- result = (vector1._x*vector2._x) + (vector1._y*vector2._y) + (vector1._z*vector2._z);
- cout<<"Dot Product: "<<result;
- cout<<" \n";
- return result;
- }
Add Comment
Please, Sign In to add comment