GteDistPoint3Tetrahedron3.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 <limits>
13 
14 namespace gte
15 {
16 
17 template <typename Real>
18 class DCPQuery<Real, Vector3<Real>, Tetrahedron3<Real>>
19 {
20 public:
21  struct Result
22  {
25  };
26 
27  Result operator()(Vector3<Real> const& point,
28  Tetrahedron3<Real> const& tetrahedron);
29 };
30 
31 
32 template <typename Real>
35  Vector3<Real> const& point, Tetrahedron3<Real> const& tetrahedron)
36 {
37  Result result;
38 
39  // Construct the planes for the faces of the tetrahedron. The normals
40  // are outer pointing, but specified not to be unit length. We only need
41  // to know sidedness of the query point, so we will save cycles by not
42  // computing unit-length normals.
43  Plane3<Real> planes[4];
44  tetrahedron.GetPlanes(planes);
45 
46  // Determine which faces are visible to the query point. Only these
47  // need to be processed by point-to-triangle distance queries.
48  result.sqrDistance = std::numeric_limits<Real>::max();
49  result.tetrahedronClosestPoint = Vector3<Real>::Zero();
50  for (int i = 0; i < 4; ++i)
51  {
52  if (Dot(planes[i].normal, point) >= planes[i].constant)
53  {
54  int indices[3] = { 0, 0, 0 };
55  tetrahedron.GetFaceIndices(i, indices);
56  Triangle3<Real> triangle(
57  tetrahedron.v[indices[0]],
58  tetrahedron.v[indices[1]],
59  tetrahedron.v[indices[2]]);
60 
62  auto ptResult = query(point, triangle);
63  if (ptResult.sqrDistance < result.sqrDistance)
64  {
65  result.sqrDistance = ptResult.sqrDistance;
66  result.tetrahedronClosestPoint = ptResult.closest;
67  }
68  }
69  }
70 
71  if (result.sqrDistance == std::numeric_limits<Real>::max())
72  {
73  // The query point is inside the solid tetrahedron. Report a zero
74  // distance. The closest points are identical.
75  result.sqrDistance = (Real)0;
76  result.tetrahedronClosestPoint = point;
77  }
78  result.distance = sqrt(result.sqrDistance);
79  return result;
80 }
81 
82 
83 }
GLsizei GLsizei GLfloat distance
Definition: glext.h:9704
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLsizei GLenum const void * indices
Definition: glcorearb.h:401
static Vector Zero()
Definition: GteVector.h:295
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
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