You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.4KB

  1. #ifndef STK_VECTOR3D_H
  2. #define STK_VECTOR3D_H
  3. #include "Stk.h"
  4. #include <cmath>
  5. namespace stk {
  6. /***************************************************/
  7. /*! \class Vector3D
  8. \brief STK 3D vector class.
  9. This class implements a three-dimensional vector.
  10. by Perry R. Cook, 1995--2017.
  11. */
  12. /***************************************************/
  13. class Vector3D : public Stk
  14. {
  15. public:
  16. //! Default constructor taking optional initial X, Y, and Z values.
  17. Vector3D( StkFloat x = 0.0, StkFloat y = 0.0, StkFloat z = 0.0 ) { setXYZ( x, y, z ); };
  18. //! Get the current X value.
  19. StkFloat getX( void ) { return X_; };
  20. //! Get the current Y value.
  21. StkFloat getY( void ) { return Y_; };
  22. //! Get the current Z value.
  23. StkFloat getZ( void ) { return Z_; };
  24. //! Calculate the vector length.
  25. StkFloat getLength( void );
  26. //! Set the X, Y, and Z values simultaniously.
  27. void setXYZ( StkFloat x, StkFloat y, StkFloat z ) { X_ = x; Y_ = y; Z_ = z; };
  28. //! Set the X value.
  29. void setX( StkFloat x ) { X_ = x; };
  30. //! Set the Y value.
  31. void setY( StkFloat y ) { Y_ = y; };
  32. //! Set the Z value.
  33. void setZ( StkFloat z ) { Z_ = z; };
  34. protected:
  35. StkFloat X_;
  36. StkFloat Y_;
  37. StkFloat Z_;
  38. };
  39. inline StkFloat Vector3D :: getLength( void )
  40. {
  41. StkFloat temp;
  42. temp = X_ * X_;
  43. temp += Y_ * Y_;
  44. temp += Z_ * Z_;
  45. temp = sqrt( temp );
  46. return temp;
  47. }
  48. } // stk namespace
  49. #endif