GteDistSegment3AlignedBox3.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.1 (2016/11/17)
7 
8 #pragma once
9 
11 #include <Mathematics/GteSegment.h>
12 
13 namespace gte
14 {
15 
16 template <typename Real>
17 class DCPQuery<Real, Segment3<Real>, AlignedBox3<Real>>
18 {
19 public:
20  struct Result
21  {
24  Vector3<Real> closestPoint[2];
25  };
26 
27  Result operator()(Segment3<Real> const& segment,
28  AlignedBox3<Real> const& box);
29 };
30 
31 
32 template <typename Real>
35  Segment3<Real> const& segment, AlignedBox3<Real> const& box)
36 {
37  Result result;
38 
39  Vector3<Real> segCenter, segDirection;
40  Real segExtent;
41  segment.GetCenteredForm(segCenter, segDirection, segExtent);
42 
43  Line3<Real> line(segCenter, segDirection);
45  auto lbResult = lbQuery(line, box);
46 
47  if (lbResult.lineParameter >= -segExtent)
48  {
49  if (lbResult.lineParameter <= segExtent)
50  {
51  result.sqrDistance = lbResult.sqrDistance;
52  result.distance = lbResult.distance;
53  result.segmentParameter = lbResult.lineParameter;
54  result.closestPoint[0] = lbResult.closestPoint[0];
55  result.closestPoint[1] = lbResult.closestPoint[1];
56  }
57  else
58  {
60  Vector3<Real> point = segCenter + segExtent*segDirection;
61  auto pbResult = pbQuery(point, box);
62  result.sqrDistance = pbResult.sqrDistance;
63  result.distance = pbResult.distance;
64  result.segmentParameter = segExtent;
65  result.closestPoint[0] = point;
66  result.closestPoint[1] = pbResult.boxClosest;
67  }
68  }
69  else
70  {
72  Vector3<Real> point = segCenter - segExtent*segDirection;
73  auto pbResult = pbQuery(point, box);
74  result.sqrDistance = pbResult.sqrDistance;
75  result.distance = pbResult.distance;
76  result.segmentParameter = -segExtent;
77  result.closestPoint[0] = point;
78  result.closestPoint[1] = pbResult.boxClosest;
79  }
80  return result;
81 }
82 
83 
84 }
GLsizei GLsizei GLfloat distance
Definition: glext.h:9704
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 03:59:59