GteIntrSegment2OrientedBox2.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 
13 // The queries consider the box to be a solid.
14 //
15 // The test-intersection queries use the method of separating axes. The
16 // find-intersection queries use parametric clipping against the four edges of
17 // the box.
18 
19 namespace gte
20 {
21 
22 template <typename Real>
23 class TIQuery<Real, Segment2<Real>, OrientedBox2<Real>>
24  :
25  public TIQuery<Real, Segment2<Real>, AlignedBox2<Real>>
26 {
27 public:
28  struct Result
29  :
30  public TIQuery<Real, Segment2<Real>, AlignedBox2<Real>>::Result
31  {
32  // No additional information to compute.
33  };
34 
35  Result operator()(Segment2<Real> const& segment,
36  OrientedBox2<Real> const& box);
37 };
38 
39 template <typename Real>
40 class FIQuery<Real, Segment2<Real>, OrientedBox2<Real>>
41  :
42  public FIQuery<Real, Segment2<Real>, AlignedBox2<Real>>
43 {
44 public:
45  struct Result
46  :
47  public FIQuery<Real, Segment2<Real>, AlignedBox2<Real>>::Result
48  {
49  // The base class parameter[] values are t-values for the
50  // segment parameterization (1-t)*p[0] + t*p[1], where t in [0,1].
51  // The values in this class are s-values for the centered form
52  // C + s * D, where s in [-e,e] and e is the extent of the segment.
53  std::array<Real, 2> cdeParameter;
54  };
55 
56  Result operator()(Segment2<Real> const& segment,
57  OrientedBox2<Real> const& box);
58 };
59 
60 
61 template <typename Real>
64  Segment2<Real> const& segment, OrientedBox2<Real> const& box)
65 {
66  // Transform the segment to the oriented-box coordinate system.
67  Vector2<Real> tmpOrigin, tmpDirection;
68  Real segExtent;
69  segment.GetCenteredForm(tmpOrigin, tmpDirection, segExtent);
70  Vector2<Real> diff = tmpOrigin - box.center;
71  Vector2<Real> segOrigin
72  {
73  Dot(diff, box.axis[0]),
74  Dot(diff, box.axis[1])
75  };
76  Vector2<Real> segDirection
77  {
78  Dot(tmpDirection, box.axis[0]),
79  Dot(tmpDirection, box.axis[1])
80  };
81 
82  Result result;
83  this->DoQuery(segOrigin, segDirection, segExtent, box.extent, result);
84  return result;
85 }
86 
87 template <typename Real>
90  Segment2<Real> const& segment, OrientedBox2<Real> const& box)
91 {
92  // Transform the segment to the oriented-box coordinate system.
93  Vector2<Real> tmpOrigin, tmpDirection;
94  Real segExtent;
95  segment.GetCenteredForm(tmpOrigin, tmpDirection, segExtent);
96  Vector2<Real> diff = tmpOrigin - box.center;
97  Vector2<Real> segOrigin
98  {
99  Dot(diff, box.axis[0]),
100  Dot(diff, box.axis[1])
101  };
102  Vector2<Real> segDirection
103  {
104  Dot(tmpDirection, box.axis[0]),
105  Dot(tmpDirection, box.axis[1])
106  };
107 
108  Result result;
109  this->DoQuery(segOrigin, segDirection, segExtent, box.extent, result);
110  for (int i = 0; i < result.numIntersections; ++i)
111  {
112  // Compute the segment in the aligned-box coordinate system and then
113  // translate it back to the original coordinates using the box cener.
114  result.point[i] = box.center + (segOrigin + result.parameter[i] * segDirection);
115  result.cdeParameter[i] = result.parameter[i];
116 
117  // Convert the parameters from the centered form to the endpoint form.
118  result.parameter[i] = (result.parameter[i] / segExtent + (Real)1) * (Real)0.5;
119  }
120  return result;
121 }
122 
123 
124 }
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
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 04:00:00