IntrLine2Arc2.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/IntrLine2Circle2.h>
  9. #include <Mathematics/Arc2.h>
  10. // The queries consider the arc to be a 1-dimensional object.
  11. namespace WwiseGTE
  12. {
  13. template <typename Real>
  14. class TIQuery<Real, Line2<Real>, Arc2<Real>>
  15. {
  16. public:
  17. struct Result
  18. {
  19. bool intersect;
  20. };
  21. Result operator()(Line2<Real> const& line, Arc2<Real> const& arc)
  22. {
  23. Result result;
  24. FIQuery<Real, Line2<Real>, Arc2<Real>> laQuery;
  25. auto laResult = laQuery(line, arc);
  26. result.intersect = laResult.intersect;
  27. return result;
  28. }
  29. };
  30. template <typename Real>
  31. class FIQuery<Real, Line2<Real>, Arc2<Real>>
  32. {
  33. public:
  34. struct Result
  35. {
  36. bool intersect;
  37. int numIntersections;
  38. std::array<Real, 2> parameter;
  39. std::array<Vector2<Real>, 2> point;
  40. };
  41. Result operator()(Line2<Real> const& line, Arc2<Real> const& arc)
  42. {
  43. Result result;
  44. FIQuery<Real, Line2<Real>, Circle2<Real>> lcQuery;
  45. Circle2<Real> circle(arc.center, arc.radius);
  46. auto lcResult = lcQuery(line, circle);
  47. if (lcResult.intersect)
  48. {
  49. // Test whether line-circle intersections are on the arc.
  50. result.numIntersections = 0;
  51. for (int i = 0; i < lcResult.numIntersections; ++i)
  52. {
  53. if (arc.Contains(lcResult.point[i]))
  54. {
  55. result.intersect = true;
  56. result.parameter[result.numIntersections]
  57. = lcResult.parameter[i];
  58. result.point[result.numIntersections++]
  59. = lcResult.point[i];
  60. }
  61. }
  62. }
  63. else
  64. {
  65. result.intersect = false;
  66. result.numIntersections = 0;
  67. }
  68. return result;
  69. }
  70. };
  71. }