GteIntrAlignedBox2OrientedBox2.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Mathematics/GteVector2.h>
13 #include <Mathematics/GteFIQuery.h>
14 #include <Mathematics/GteTIQuery.h>
15 
16 // The queries consider the box to be a solid.
17 //
18 // The test-intersection query uses the method of separating axes. The set of
19 // potential separating directions includes the 2 edge normals of box0 and the
20 // 2 edge normals of box1. The integer 'separating' identifies the axis that
21 // reported separation; there may be more than one but only one is reported.
22 // The value is 0 when box0.axis[0] separates, 1 when box0.axis[1] separates,
23 // 2 when box1.axis[0] separates, or 3 when box1.axis[1] separates.
24 
25 namespace gte
26 {
27 
28 template <typename Real>
29 class TIQuery<Real, AlignedBox2<Real>, OrientedBox2<Real>>
30 {
31 public:
32  struct Result
33  {
34  bool intersect;
36  };
37 
38  Result operator()(AlignedBox2<Real> const& box0,
39  OrientedBox2<Real> const& box1);
40 };
41 
42 
43 template <typename Real>
46  AlignedBox2<Real> const& box0, OrientedBox2<Real> const& box1)
47 {
48  Result result;
49 
50  // Get the centered form of the aligned box. The axes are implicitly
51  // A0[0] = (1,0) and A0[1] = (0,1).
52  Vector2<Real> C0, E0;
53  box0.GetCenteredForm(C0, E0);
54 
55  // Convenience variables.
56  Vector2<Real> const& C1 = box1.center;
57  Vector2<Real> const* A1 = &box1.axis[0];
58  Vector2<Real> const& E1 = box1.extent;
59 
60  // Compute difference of box centers.
61  Vector2<Real> D = C1 - C0;
62 
63  Real absDot01[2][2], rSum;
64 
65  // Test box0.axis[0] = (1,0).
66  absDot01[0][0] = std::abs(A1[0][0]);
67  absDot01[0][1] = std::abs(A1[1][0]);
68  rSum = E0[0] + E1[0] * absDot01[0][0] + E1[1] * absDot01[0][1];
69  if (std::abs(D[0]) > rSum)
70  {
71  result.intersect = false;
72  result.separating = 0;
73  return result;
74  }
75 
76  // Test axis box0.axis[1] = (0,1).
77  absDot01[1][0] = std::abs(A1[0][1]);
78  absDot01[1][1] = std::abs(A1[1][1]);
79  rSum = E0[1] + E1[0] * absDot01[1][0] + E1[1] * absDot01[1][1];
80  if (std::abs(D[1]) > rSum)
81  {
82  result.intersect = false;
83  result.separating = 1;
84  return result;
85  }
86 
87  // Test axis box1.axis[0].
88  rSum = E1[0] + E0[0] * absDot01[0][0] + E0[1] * absDot01[1][0];
89  if (std::abs(Dot(A1[0], D)) > rSum)
90  {
91  result.intersect = false;
92  result.separating = 2;
93  return result;
94  }
95 
96  // Test axis box1.axis[1].
97  rSum = E1[1] + E0[0] * absDot01[0][1] + E0[1] * absDot01[1][1];
98  if (std::abs(Dot(A1[1], D)) > rSum)
99  {
100  result.intersect = false;
101  result.separating = 3;
102  return result;
103  }
104 
105  result.intersect = true;
106  return result;
107 }
108 
109 
110 }
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
Definition: GteBSNumber.h:966
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLuint64EXT * result
Definition: glext.h:10003


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00