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