SHAPES.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //
  20. // shapes.cpp
  21. //
  22. //
  23. // History:
  24. // 12/08/95 BRH Started.
  25. // 12/11/95 BRH Added Ray constructor that takes two points and
  26. // calculates the unit vector for the ray.
  27. //
  28. // 11/04/96 JMI Changed:
  29. // Old label: New label:
  30. // ========= =========
  31. // C2DRay R2DRay
  32. // C3DRay R3dRay
  33. //
  34. //////////////////////////////////////////////////////////////////////////////
  35. #include "Shapes.h"
  36. //////////////////////////////////////////////////////////////////////////////
  37. //
  38. // Constructor
  39. //
  40. // Description:
  41. // Takes two points and calculates the unit vector for the ray
  42. //
  43. // Parameters:
  44. // lX1 = x coordinate of originating point
  45. // lY2 = y coordinate of originating point
  46. // lX2 = x coordinate in direction of ray
  47. // lY2 = y coordinate in direction of ray
  48. //
  49. // Returns:
  50. // none
  51. //
  52. //////////////////////////////////////////////////////////////////////////////
  53. R2DRay::R2DRay(long lX1, long lY1, long lX2, long lY2)
  54. {
  55. X = lX1;
  56. Y = lY1;
  57. fXVect = (float) lX2 - lX1;
  58. fYVect = (float) lY2 - lY1;
  59. if (fXVect > fYVect)
  60. {
  61. fYVect /= fXVect;
  62. fXVect = (float) 1.0; //dx /= dx;
  63. }
  64. else
  65. {
  66. fXVect /= fYVect;
  67. fYVect = (float) 1.0; //dy /= dy;
  68. }
  69. }
  70. R3DRay::R3DRay(long lX1, long lY1, long lZ1, long lX2, long lY2, long lZ2)
  71. {
  72. X = lX1;
  73. Y = lY1;
  74. Z = lZ1;
  75. fXVect = (float) lX2 - lX1;
  76. fYVect = (float) lY2 - lY1;
  77. fZVect = (float) lZ2 - lZ1;
  78. if (fXVect > fYVect && fXVect > fZVect)
  79. {
  80. fYVect /= fXVect;
  81. fZVect /= fXVect;
  82. fXVect = (float) 1.0; // fXVect /= fXVect;
  83. }
  84. else
  85. if (fYVect > fXVect && fYVect > fZVect)
  86. {
  87. fXVect /= fYVect;
  88. fZVect /= fYVect;
  89. fYVect = (float) 1.0; // fYVect /= fYVect;
  90. }
  91. else
  92. {
  93. fXVect /= fZVect;
  94. fYVect /= fZVect;
  95. fZVect = (float) 1.0; // fZVect /= fZVect;
  96. }
  97. }
  98. //////////////////////////////////////////////////////////////////////////////
  99. // EOF
  100. //////////////////////////////////////////////////////////////////////////////