GteIntrAlignedBox3Cylinder3.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.4.0 (2016/11/08)
7 
8 #pragma once
9 
10 #include <Mathematics/GteTIQuery.h>
15 
16 // The query considers the cylinder and box to be solids.
17 
18 namespace gte
19 {
20 
21 template <typename Real>
22 class TIQuery<Real, AlignedBox3<Real>, Cylinder3<Real>>
23 {
24 public:
25  struct Result
26  {
27  bool intersect;
28  };
29 
30  Result operator()(AlignedBox3<Real> const& box, Cylinder3<Real> const& cylinder);
31 
32 private:
33 };
34 
35 
36 template <typename Real>
39  AlignedBox3<Real> const& box, Cylinder3<Real> const& cylinder)
40 {
41  Result result;
42 
43  // Translate the box and cylinder so that the box is in the first octant
44  // where all points in the box have nonnegative components.
45  Vector3<Real> corner = box.max - box.min;
46  Vector3<Real> origin = cylinder.axis.origin - box.min;
47  Vector3<Real> direction = cylinder.axis.direction;
48 
49  // Compute quantities to initialize q and M in the LCP.
50  Real halfHeight = cylinder.height * (Real)0.5;
51  Matrix3x3<Real> P = (Matrix3x3<Real>::Identity() - OuterProduct(direction, direction));
52  Vector3<Real> C = -(P * origin);
53  Real originDotDirection = Dot(origin, direction);
54 
56  A.SetRow(0, { (Real)-1, (Real) 0, (Real) 0 });
57  A.SetRow(1, { (Real) 0, (Real)-1, (Real) 0 });
58  A.SetRow(2, { (Real) 0, (Real) 0, (Real)-1 });
59  A.SetRow(3, direction);
60  A.SetRow(4, -direction);
61 
62  Vector<5, Real> B =
63  {
64  -corner[0],
65  -corner[1],
66  -corner[2],
67  originDotDirection - halfHeight,
68  -originDotDirection - halfHeight
69  };
70 
71  std::array<std::array<Real, 8>, 8> M;
72  for (int r = 0; r < 3; ++r)
73  {
74  for (int c = 0; c < 3; ++c)
75  {
76  M[r][c] = P(r, c);
77  }
78 
79  for (int c = 3, i = 0; c < 8; ++c, ++i)
80  {
81  M[r][c] = -A(i, r);
82  }
83  }
84 
85  for (int r = 3, i = 0; r < 8; ++r, ++i)
86  {
87  for (int c = 0; c < 3; ++c)
88  {
89  M[r][c] = A(i, c);
90  }
91 
92  for (int c = 3; c < 8; ++c)
93  {
94  M[r][c] = (Real)0;
95  }
96  }
97 
98  std::array<Real, 8> q;
99  for (int r = 0; r < 3; ++r)
100  {
101  q[r] = C[r];
102  }
103 
104  for (int r = 3, i = 0; r < 8; ++r, ++i)
105  {
106  q[r] = -B[i];
107  }
108 
109  std::array<Real, 8> w, z;
110  LCPSolver<Real, 8> LCP;
111  if (LCP.Solve(q, M, w, z))
112  {
113  Vector3<Real> zSolution{ z[0], z[1], z[2] };
114  Vector3<Real> diff = zSolution - origin;
115  Real qform = Dot(diff, P * diff);
116  result.intersect = (qform <= cylinder.radius * cylinder.radius);
117  }
118  else
119  {
120  result.intersect = false;
121  }
122 
123  return result;
124 }
125 
126 }
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:852
const GLubyte * c
Definition: glext.h:11671
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:843
GLboolean r
Definition: glcorearb.h:1217
void SetRow(int r, Vector< NumCols, Real > const &vec)
Definition: GteMatrix.h:352
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:255
static Matrix Identity()
Definition: GteMatrix.h:490
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLuint64EXT * result
Definition: glext.h:10003
GMatrix< Real > OuterProduct(GVector< Real > const &U, GVector< Real > const &V)
Definition: GteGMatrix.h:815


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00