dpoint3.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**********************************************************************
  2. *<
  3. FILE: dpoint3.h
  4. DESCRIPTION:
  5. CREATED BY: Dan Silva
  6. HISTORY:
  7. *> Copyright (c) 1994, All Rights Reserved.
  8. **********************************************************************/
  9. #ifndef __DPOINT3__
  10. #define __DPOINT3__
  11. class ostream;
  12. class DPoint3 {
  13. public:
  14. double x,y,z;
  15. // Constructors
  16. DPoint3(){}
  17. DPoint3(double X, double Y, double Z) { x = X; y = Y; z = Z; }
  18. DPoint3(const DPoint3& a) { x = a.x; y = a.y; z = a.z; }
  19. DPoint3(double af[3]) { x = af[0]; y = af[1]; z = af[2]; }
  20. // Access operators
  21. double& operator[](int i) { return (&x)[i]; }
  22. const double& operator[](int i) const { return (&x)[i]; }
  23. // Conversion function
  24. operator double*() { return(&x); }
  25. // Unary operators
  26. DPoint3 operator-() const { return(DPoint3(-x,-y,-z)); }
  27. DPoint3 operator+() const { return *this; }
  28. // Assignment operators
  29. DllExport DPoint3& operator-=(const DPoint3&);
  30. DllExport DPoint3& operator+=(const DPoint3&);
  31. DllExport DPoint3& operator*=(double);
  32. DllExport DPoint3& operator/=(double);
  33. // Binary operators
  34. DllExport DPoint3 operator-(const DPoint3&) const;
  35. DllExport DPoint3 operator+(const DPoint3&) const;
  36. DllExport double operator*(const DPoint3&) const; // DOT PRODUCT
  37. DllExport DPoint3 operator^(const DPoint3&) const; // CROSS PRODUCT
  38. };
  39. double DllExport Length(const DPoint3&);
  40. int DllExport MaxComponent(const DPoint3&); // the component with the maximum abs value
  41. int DllExport MinComponent(const DPoint3&); // the component with the minimum abs value
  42. DPoint3 DllExport Normalize(const DPoint3&); // Return a unit vector.
  43. DPoint3 DllExport operator*(double, const DPoint3&); // multiply by scalar
  44. DPoint3 DllExport operator*(const DPoint3&, double); // multiply by scalar
  45. DPoint3 DllExport operator/(const DPoint3&, double); // divide by scalar
  46. ostream DllExport &operator<<(ostream&, const DPoint3&);
  47. // Inlines:
  48. inline double Length(const DPoint3& v) {
  49. return (double)sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
  50. }
  51. inline DPoint3& DPoint3::operator-=(const DPoint3& a) {
  52. x -= a.x; y -= a.y; z -= a.z;
  53. return *this;
  54. }
  55. inline DPoint3& DPoint3::operator+=(const DPoint3& a) {
  56. x += a.x; y += a.y; z += a.z;
  57. return *this;
  58. }
  59. inline DPoint3& DPoint3::operator*=(double f) {
  60. x *= f; y *= f; z *= f;
  61. return *this;
  62. }
  63. inline DPoint3& DPoint3::operator/=(double f) {
  64. x /= f; y /= f; z /= f;
  65. return *this;
  66. }
  67. inline DPoint3 DPoint3::operator-(const DPoint3& b) const {
  68. return(DPoint3(x-b.x,y-b.y,z-b.z));
  69. }
  70. inline DPoint3 DPoint3::operator+(const DPoint3& b) const {
  71. return(DPoint3(x+b.x,y+b.y,z+b.z));
  72. }
  73. inline double DPoint3::operator*(const DPoint3& b) const {
  74. return(x*b.x+y*b.y+z*b.z);
  75. }
  76. inline DPoint3 operator*(double f, const DPoint3& a) {
  77. return(DPoint3(a.x*f, a.y*f, a.z*f));
  78. }
  79. inline DPoint3 operator*(const DPoint3& a, double f) {
  80. return(DPoint3(a.x*f, a.y*f, a.z*f));
  81. }
  82. inline DPoint3 operator/(const DPoint3& a, double f) {
  83. return(DPoint3(a.x/f, a.y/f, a.z/f));
  84. }
  85. DPoint3 DllExport CrossProd(const DPoint3& a, const DPoint3& b); // CROSS PRODUCT
  86. double DllExport DotProd(const DPoint3& a, const DPoint3& b) ; // DOT PRODUCT
  87. #endif