GteDistSegment3Triangle3.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>, Triangle3<Real>>
19 {
20 public:
21  struct Result
22  {
24  Real segmentParameter, triangleParameter[3];
25  Vector3<Real> closestPoint[2];
26  };
27 
28  Result operator()(Segment3<Real> const& segment,
29  Triangle3<Real> const& triangle);
30 };
31 
32 
33 template <typename Real>
36  Segment3<Real> const& segment, Triangle3<Real> const& triangle)
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 ltResult = ltQuery(line, triangle);
47 
48  if (ltResult.lineParameter >= -segExtent)
49  {
50  if (ltResult.lineParameter <= segExtent)
51  {
52  result.distance = ltResult.distance;
53  result.sqrDistance = ltResult.sqrDistance;
54  result.segmentParameter = ltResult.lineParameter;
55  result.triangleParameter[0] = ltResult.triangleParameter[0];
56  result.triangleParameter[1] = ltResult.triangleParameter[1];
57  result.triangleParameter[2] = ltResult.triangleParameter[2];
58  result.closestPoint[0] = ltResult.closestPoint[0];
59  result.closestPoint[1] = ltResult.closestPoint[1];
60  }
61  else
62  {
64  Vector3<Real> point = segCenter + segExtent*segDirection;
65  auto ptResult = ptQuery(point, triangle);
66  result.sqrDistance = ptResult.sqrDistance;
67  result.distance = ptResult.distance;
68  result.segmentParameter = segExtent;
69  result.closestPoint[0] = point;
70  result.closestPoint[1] = ptResult.closest;
71  }
72  }
73  else
74  {
76  Vector3<Real> point = segCenter - segExtent*segDirection;
77  auto ptResult = ptQuery(point, triangle);
78  result.sqrDistance = ptResult.sqrDistance;
79  result.distance = ptResult.distance;
80  result.segmentParameter = segExtent;
81  result.closestPoint[0] = point;
82  result.closestPoint[1] = ptResult.closest;
83  }
84  return result;
85 }
86 
87 
88 }
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