GteDistSegment3Rectangle3.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/GteSegment.h>
13 
14 namespace gte
15 {
16 
17 template <typename Real>
18 class DCPQuery<Real, Segment3<Real>, Rectangle3<Real>>
19 {
20 public:
21  struct Result
22  {
24  Real segmentParameter, rectangleParameter[2];
25  Vector3<Real> closestPoint[2];
26  };
27 
28  Result operator()(Segment3<Real> const& segment,
29  Rectangle3<Real> const& rectangle);
30 };
31 
32 
33 template <typename Real>
36  Segment3<Real> const& segment, Rectangle3<Real> const& rectangle)
37 {
38  Result result;
39 
40  Vector3<Real> segCenter, segDirection;
41  Real segExtent;
42  segment.GetCenteredForm(segCenter, segDirection, segExtent);
43 
44  Line3<Real> line(segCenter, segDirection);
46  auto lrResult = lrQuery(line, rectangle);
47 
48  if (lrResult.lineParameter >= -segExtent)
49  {
50  if (lrResult.lineParameter <= segExtent)
51  {
52  result.distance = lrResult.distance;
53  result.sqrDistance = lrResult.sqrDistance;
54  result.segmentParameter = lrResult.lineParameter;
55  result.rectangleParameter[0] = lrResult.rectangleParameter[0];
56  result.rectangleParameter[1] = lrResult.rectangleParameter[1];
57  result.closestPoint[0] = lrResult.closestPoint[0];
58  result.closestPoint[1] = lrResult.closestPoint[1];
59  }
60  else
61  {
63  Vector3<Real> point = segCenter + segExtent*segDirection;
64  auto prResult = prQuery(point, rectangle);
65  result.sqrDistance = prResult.sqrDistance;
66  result.distance = prResult.distance;
67  result.segmentParameter = segExtent;
68  result.closestPoint[0] = point;
69  result.closestPoint[1] = prResult.rectangleClosestPoint;
70  }
71  }
72  else
73  {
75  Vector3<Real> point = segCenter - segExtent*segDirection;
76  auto prResult = prQuery(point, rectangle);
77  result.sqrDistance = prResult.sqrDistance;
78  result.distance = prResult.distance;
79  result.segmentParameter = segExtent;
80  result.closestPoint[0] = point;
81  result.closestPoint[1] = prResult.rectangleClosestPoint;
82  }
83  return result;
84 }
85 
86 
87 }
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