IntrSegment2Arc2.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/IntrSegment2Circle2.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, Segment2<Real>, Arc2<Real>>
  15. {
  16. public:
  17. struct Result
  18. {
  19. bool intersect;
  20. };
  21. Result operator()(Segment2<Real> const& segment, Arc2<Real> const& arc)
  22. {
  23. Result result;
  24. FIQuery<Real, Segment2<Real>, Arc2<Real>> saQuery;
  25. auto saResult = saQuery(segment, arc);
  26. result.intersect = saResult.intersect;
  27. return result;
  28. }
  29. };
  30. template <typename Real>
  31. class FIQuery<Real, Segment2<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()(Segment2<Real> const& segment, Arc2<Real> const& arc)
  42. {
  43. Result result;
  44. result.intersect = false;
  45. result.numIntersections = 0;
  46. result.parameter[0] = (Real)0;
  47. result.parameter[0] = (Real)0;
  48. result.point[0] = { (Real)0, (Real)0 };
  49. result.point[1] = { (Real)0, (Real)0 };
  50. FIQuery<Real, Segment2<Real>, Circle2<Real>> scQuery;
  51. Circle2<Real> circle(arc.center, arc.radius);
  52. auto scResult = scQuery(segment, circle);
  53. if (scResult.intersect)
  54. {
  55. // Test whether line-circle intersections are on the arc.
  56. for (int i = 0; i < scResult.numIntersections; ++i)
  57. {
  58. if (arc.Contains(scResult.point[i]))
  59. {
  60. result.intersect = true;
  61. result.parameter[result.numIntersections] = scResult.parameter[i];
  62. result.point[result.numIntersections++] = scResult.point[i];
  63. }
  64. }
  65. }
  66. return result;
  67. }
  68. };
  69. }