GteDistAlignedBoxAlignedBox.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.5.0 (2016/11/26)
7 
8 #pragma once
9 
14 
15 namespace gte
16 {
17 
18 template <int N, typename Real>
19 class DCPQuery<Real, AlignedBox<N, Real>, AlignedBox<N, Real>>
20 {
21 public:
22  struct Result
23  {
25 
26  // To compute a single closest point on each box, use
27  // Vector<N, Real> closest0 = (closestPoints[0].min + closestPoints[0].max)/2;
28  // Vector<N, Real> closest1 = (closestPoints[1].min + closestPoints[1].max)/2;
29  AlignedBox<N, Real> closestPoints[2];
30  };
31 
32  Result operator()(AlignedBox<N, Real> const& box0, AlignedBox<N, Real> const& box1);
33 };
34 
35 
36 template <int N, typename Real>
38 DCPQuery<Real, AlignedBox<N, Real>, AlignedBox<N, Real>>::operator()(
39  AlignedBox<N, Real> const& box0, AlignedBox<N, Real> const& box1)
40 {
41  Result result;
42  result.sqrDistance = (Real)0;
43  for (int i = 0; i < N; ++i)
44  {
45  if (box0.min[i] >= box1.max[i])
46  {
47  Real delta = box0.min[i] - box1.min[i];
48  result.sqrDistance += delta * delta;
49  result.closestPoints[0].min[i] = box0.min[i];
50  result.closestPoints[0].max[i] = box0.min[i];
51  result.closestPoints[1].min[i] = box1.max[i];
52  result.closestPoints[1].max[i] = box1.max[i];
53  }
54  else if (box1.min[i] >= box0.max[i])
55  {
56  Real delta = box1.min[i] - box0.max[i];
57  result.sqrDistance += delta * delta;
58  result.closestPoints[0].min[i] = box0.max[i];
59  result.closestPoints[0].max[i] = box0.max[i];
60  result.closestPoints[1].min[i] = box1.min[i];
61  result.closestPoints[1].max[i] = box1.min[i];
62  }
63  else
64  {
65  std::array<Real, 2> intr0 = { box0.min[i], box0.max[i] };
66  std::array<Real, 2> intr1 = { box1.min[i], box1.max[i] };
67  FIQuery<Real, std::array<Real, 2>, std::array<Real, 2>> query;
68  auto iiResult = query(intr0, intr1);
69  for (int j = 0; j < 2; ++j)
70  {
71  result.closestPoints[j].min[i] = iiResult.overlap[0];
72  result.closestPoints[j].max[i] = iiResult.overlap[1];
73  }
74  }
75  }
76  result.distance = Function<Real>::Sqrt(result.sqrDistance);
77  return result;
78 }
79 
80 }
GLsizei GLsizei GLfloat distance
Definition: glext.h:9704
static Real Sqrt(Real const &x)
Definition: GteFunctions.h:937
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLuint64EXT * result
Definition: glext.h:10003
GLenum query
Definition: glext.h:2716


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