Guest User

Untitled

a guest
Apr 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. //217CR 1st Assignment
  2. //Brendan Smith
  3. //TVector Contructors and Functions
  4.  
  5. //The Inports
  6. #include "TVector3D.h"
  7. #include <math.h>
  8. #include <iostream>
  9.  
  10. using namespace std;
  11.  
  12.  
  13. // The Default constructor
  14. TVector3D::TVector3D(void)
  15. {
  16. _x=0;
  17. _y=0;
  18. _z=0;
  19. }
  20.  
  21. // The Second constructor
  22. TVector3D::TVector3D(double vecx, double vecy, double vecz)
  23. {
  24. _x=vecx;
  25. _y=vecy;
  26. _z=vecz;
  27. }
  28.  
  29.  
  30. // Function that adds two 3D vectors together
  31. TVector3D TVector3D::AddVectors(TVector3D vector1, TVector3D vector2, TVector3D vector_result)
  32. {
  33. vector_result._x = vector1._x + vector2._x;
  34. vector_result._y = vector1._y + vector2._y;
  35. vector_result._z = vector1._z + vector2._z;
  36.  
  37.  
  38. cout<<"Addition: "<<vector_result._x<<" ,"<<vector_result._y<<" ,"<<vector_result._z;
  39. cout<<" \n";
  40.  
  41.  
  42. return vector_result;
  43. }
  44.  
  45. // Function that subtracts two 3D vectors together
  46. TVector3D TVector3D::SubstractVectors(TVector3D vector1, TVector3D vector2, TVector3D vector_result)
  47. {
  48. vector_result._x = vector1._x - vector2._x;
  49. vector_result._y = vector1._y - vector2._y;
  50. vector_result._z = vector1._z - vector2._z;
  51.  
  52.  
  53. cout<<"Subtracts: "<<vector_result._x<<" ,"<<vector_result._y<<" ,"<<vector_result._z;
  54.  
  55. cout<<" \n";
  56.  
  57.  
  58. return vector_result;
  59. }
  60.  
  61. // Function that Crosses two 3D vectors together.
  62. TVector3D TVector3D::CrossVectors(TVector3D vector1, TVector3D vector2, TVector3D vector_result)
  63. {
  64. vector_result._x = (vector1._y * vector2._z) - (vector1._z * vector2._y);
  65. vector_result._y = (vector1._x * vector2._z) - (vector1._z * vector2._x);
  66. vector_result._z = (vector1._x * vector2._y) - (vector1._z * vector2._x);
  67.  
  68.  
  69.  
  70. cout<<"Cross: "<<vector_result._x<<" ,"<<vector_result._y<<" ,"<<vector_result._z;
  71. cout<<" \n";
  72.  
  73.  
  74. return vector_result;
  75. }
  76.  
  77.  
  78. //Function that finds the Magnitude of a 3D vectors.
  79. double TVector3D::MagnitudeVectors(TVector3D vector1)
  80. {
  81. double result;
  82. result = sqrt((vector1._x * vector1._x) + (vector1._y * vector1._y) + (vector1._z * vector1._z));
  83.  
  84. cout<<"Magnitude: "<<result;
  85. cout<<" \n";
  86.  
  87.  
  88. return result;
  89. }
  90.  
  91.  
  92. // Function that finds the Unit of a 3D vectors.
  93. TVector3D TVector3D::UnitVectors(TVector3D vector1, TVector3D vector_result)
  94. {
  95. double length = TVector3D::MagnitudeVectors(vector1);
  96. vector_result._x = vector1._x / length;
  97. vector_result._y = vector1._y / length;
  98. vector_result._z = vector1._z / length;
  99.  
  100. cout<<"Unit: "<<vector_result._x<<" ,"<<vector_result._y<<" ,"<<vector_result._z;
  101. cout<<" \n";
  102.  
  103.  
  104. return vector_result;
  105.  
  106. }
  107.  
  108. // Function that Inverts a 3D vectors.
  109. TVector3D TVector3D::InvertVectors(TVector3D vector1, TVector3D vector_result)
  110. {
  111. vector_result._x = -vector1._x;
  112. vector_result._y = -vector1._y;
  113. vector_result._z = -vector1._z;
  114.  
  115. cout<<"Invert: "<<vector_result._x<<" ,"<<vector_result._y<<" ,"<<vector_result._z;
  116. cout<<" \n";
  117.  
  118.  
  119. return vector_result;
  120. }
  121.  
  122. // Function that finds the Dot Produc of two 3D vectors.
  123. double TVector3D::DotProductVectors(TVector3D vector1, TVector3D vector2, double result)
  124. {
  125. result = (vector1._x*vector2._x) + (vector1._y*vector2._y) + (vector1._z*vector2._z);
  126.  
  127. cout<<"Dot Product: "<<result;
  128. cout<<" \n";
  129.  
  130.  
  131. return result;
  132. }
Add Comment
Please, Sign In to add comment