GteIntrHalfspace3OrientedBox3.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/GteFIQuery.h>
13 #include <Mathematics/GteTIQuery.h>
14 
15 // Queries for intersection of objects with halfspaces. These are useful for
16 // containment testing, object culling, and clipping.
17 
18 namespace gte
19 {
20 
21 template <typename Real>
22 class TIQuery<Real, Halfspace3<Real>, OrientedBox3<Real>>
23 {
24 public:
25  struct Result
26  {
27  bool intersect;
28  };
29 
30  Result operator()(Halfspace3<Real> const& halfspace,
31  OrientedBox3<Real> const& box);
32 };
33 
34 
35 template <typename Real>
38  Halfspace3<Real> const& halfspace, OrientedBox3<Real> const& box)
39 {
40  Result result;
41 
42  // Project the box center onto the normal line. The plane of the
43  // halfspace occurs at the origin (zero) of the normal line.
44  Real center = Dot(halfspace.normal, box.center) - halfspace.constant;
45 
46  // Compute the radius of the interval of projection.
47  Real radius =
48  std::abs(box.extent[0] * Dot(halfspace.normal, box.axis[0])) +
49  std::abs(box.extent[1] * Dot(halfspace.normal, box.axis[1])) +
50  std::abs(box.extent[2] * Dot(halfspace.normal, box.axis[2]));
51 
52  // The box and halfspace intersect when the projection interval maximum
53  // is nonnegative.
54  result.intersect = (center + radius >= (Real)0);
55  return result;
56 }
57 
58 
59 }
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
Definition: GteBSNumber.h:966
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