GteDistRectangle3Rectangle3.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 
11 
12 namespace gte
13 {
14 
15 template <typename Real>
16 class DCPQuery<Real, Rectangle3<Real>, Rectangle3<Real>>
17 {
18 public:
19  struct Result
20  {
22  Real rectangle0Parameter[2], rectangle1Parameter[2];
23  Vector3<Real> closestPoint[2];
24  };
25 
26  Result operator()(Rectangle3<Real> const& rectangle0,
27  Rectangle3<Real> const& rectangle1);
28 };
29 
30 
31 template <typename Real>
34  Rectangle3<Real> const& rectangle0, Rectangle3<Real> const& rectangle1)
35 {
36  Result result;
37 
40  srResult;
41  result.sqrDistance = std::numeric_limits<Real>::max();
42 
43  // Compare edges of rectangle0 to the interior of rectangle1.
44  for (int i1 = 0; i1 < 2; ++i1)
45  {
46  for (int i0 = -1; i0 <= 1; i0 += 2)
47  {
48  Real s = i0 * rectangle0.extent[1 - i1];
49  Vector3<Real> segCenter = rectangle0.center +
50  s * rectangle0.axis[1 - i1];
51  Segment3<Real> edge(segCenter, rectangle0.axis[i1],
52  rectangle0.extent[i1]);
53 
54  srResult = srQuery(edge, rectangle1);
55  if (srResult.sqrDistance < result.sqrDistance)
56  {
57  result.distance = srResult.distance;
58  result.sqrDistance = srResult.sqrDistance;
59  result.rectangle0Parameter[i1] = s;
60  result.rectangle0Parameter[1 - i1] =
61  srResult.segmentParameter;
62  result.rectangle1Parameter[0] =
63  srResult.rectangleParameter[0];
64  result.rectangle1Parameter[1] =
65  srResult.rectangleParameter[1];
66  result.closestPoint[0] = srResult.closestPoint[0];
67  result.closestPoint[1] = srResult.closestPoint[1];
68  }
69  }
70  }
71 
72  // Compare edges of rectangle1 to the interior of rectangle0.
73  for (int i1 = 0; i1 < 2; ++i1)
74  {
75  for (int i0 = -1; i0 <= 1; i0 += 2)
76  {
77  Real s = i0 * rectangle1.extent[1 - i1];
78  Vector3<Real> segCenter = rectangle1.center +
79  s * rectangle1.axis[1 - i1];
80  Segment3<Real> edge(segCenter, rectangle0.axis[i1],
81  rectangle0.extent[i1]);
82 
83  srResult = srQuery(edge, rectangle0);
84  if (srResult.sqrDistance < result.sqrDistance)
85  {
86  result.distance = srResult.distance;
87  result.sqrDistance = srResult.sqrDistance;
88  result.rectangle0Parameter[0] =
89  srResult.rectangleParameter[0];
90  result.rectangle0Parameter[1] =
91  srResult.rectangleParameter[1];
92  result.rectangle1Parameter[i1] = s;
93  result.rectangle1Parameter[1 - i1] =
94  srResult.segmentParameter;
95  result.closestPoint[0] = srResult.closestPoint[1];
96  result.closestPoint[1] = srResult.closestPoint[0];
97  }
98  }
99  }
100  return result;
101 }
102 
103 
104 }
GLsizei GLsizei GLfloat distance
Definition: glext.h:9704
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLdouble s
Definition: glext.h:231
GLuint64EXT * result
Definition: glext.h:10003


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59