GteDistPoint3Rectangle3.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 
10 #include <Mathematics/GteVector3.h>
13 
14 namespace gte
15 {
16 
17 template <typename Real>
18 class DCPQuery<Real, Vector3<Real>, Rectangle3<Real>>
19 {
20 public:
21  struct Result
22  {
24  Real rectangleParameter[2];
26  };
27 
28  Result operator()(Vector3<Real> const& point,
29  Rectangle3<Real> const& rectangle);
30 };
31 
32 
33 template <typename Real>
36  Vector3<Real> const& point, Rectangle3<Real> const& rectangle)
37 {
38  Result result;
39 
40  Vector3<Real> diff = rectangle.center - point;
41  Real b0 = Dot(diff, rectangle.axis[0]);
42  Real b1 = Dot(diff, rectangle.axis[1]);
43  Real s0 = -b0, s1 = -b1;
44  result.sqrDistance = Dot(diff, diff);
45 
46  if (s0 < -rectangle.extent[0])
47  {
48  s0 = -rectangle.extent[0];
49  }
50  else if (s0 > rectangle.extent[0])
51  {
52  s0 = rectangle.extent[0];
53  }
54  result.sqrDistance += s0*(s0 + ((Real)2)*b0);
55 
56  if (s1 < -rectangle.extent[1])
57  {
58  s1 = -rectangle.extent[1];
59  }
60  else if (s1 > rectangle.extent[1])
61  {
62  s1 = rectangle.extent[1];
63  }
64  result.sqrDistance += s1*(s1 + ((Real)2)*b1);
65 
66  // Account for numerical round-off error.
67  if (result.sqrDistance < (Real)0)
68  {
69  result.sqrDistance = (Real)0;
70  }
71 
72  result.distance = sqrt(result.sqrDistance);
73  result.rectangleParameter[0] = s0;
74  result.rectangleParameter[1] = s1;
75  result.rectangleClosestPoint = rectangle.center;
76  for (int i = 0; i < 2; ++i)
77  {
78  result.rectangleClosestPoint +=
79  result.rectangleParameter[i] * rectangle.axis[i];
80  }
81  return result;
82 }
83 
84 
85 }
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s0
Definition: glext.h:9013
GLsizei GLsizei GLfloat distance
Definition: glext.h:9704
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
Definition: glext.h:9013
GLuint64EXT * result
Definition: glext.h:10003


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59