Cylinder3.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2019.08.13
  7. #pragma once
  8. #include <Mathematics/Line.h>
  9. // The cylinder axis is a line. The origin of the cylinder is chosen to be
  10. // the line origin. The cylinder wall is at a distance R units from the axis.
  11. // An infinite cylinder has infinite height. A finite cylinder has center C
  12. // at the line origin and has a finite height H. The segment for the finite
  13. // cylinder has endpoints C-(H/2)*D and C+(H/2)*D where D is a unit-length
  14. // direction of the line.
  15. namespace WwiseGTE
  16. {
  17. template <typename Real>
  18. class Cylinder3
  19. {
  20. public:
  21. // Construction and destruction. The default constructor sets axis
  22. // to (0,0,1), radius to 1, and height to 1.
  23. Cylinder3()
  24. :
  25. axis(Line3<Real>()),
  26. radius((Real)1),
  27. height((Real)1)
  28. {
  29. }
  30. Cylinder3(Line3<Real> const& inAxis, Real inRadius, Real inHeight)
  31. :
  32. axis(inAxis),
  33. radius(inRadius),
  34. height(inHeight)
  35. {
  36. }
  37. Line3<Real> axis;
  38. Real radius, height;
  39. public:
  40. // Comparisons to support sorted containers.
  41. bool operator==(Cylinder3 const& cylinder) const
  42. {
  43. return axis == cylinder.axis
  44. && radius == cylinder.radius
  45. && height == cylinder.height;
  46. }
  47. bool operator!=(Cylinder3 const& cylinder) const
  48. {
  49. return !operator==(cylinder);
  50. }
  51. bool operator< (Cylinder3 const& cylinder) const
  52. {
  53. if (axis < cylinder.axis)
  54. {
  55. return true;
  56. }
  57. if (axis > cylinder.axis)
  58. {
  59. return false;
  60. }
  61. if (radius < cylinder.radius)
  62. {
  63. return true;
  64. }
  65. if (radius > cylinder.radius)
  66. {
  67. return false;
  68. }
  69. return height < cylinder.height;
  70. }
  71. bool operator<=(Cylinder3 const& cylinder) const
  72. {
  73. return !cylinder.operator<(*this);
  74. }
  75. bool operator> (Cylinder3 const& cylinder) const
  76. {
  77. return cylinder.operator<(*this);
  78. }
  79. bool operator>=(Cylinder3 const& cylinder) const
  80. {
  81. return !operator<(cylinder);
  82. }
  83. };
  84. }