GteIntrHalfspace3Cylinder3.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>, Cylinder3<Real>>
23 {
24 public:
25  struct Result
26  {
27  bool intersect;
28  };
29 
30  Result operator()(Halfspace3<Real> const& halfspace,
31  Cylinder3<Real> const& cylinder);
32 };
33 
34 
35 template <typename Real>
38  Halfspace3<Real> const& halfspace, Cylinder3<Real> const& cylinder)
39 {
40  Result result;
41 
42  // Compute extremes of signed distance Dot(N,X)-d for points on the
43  // cylinder. These are
44  // min = (Dot(N,C)-d) - r*sqrt(1-Dot(N,W)^2) - (h/2)*|Dot(N,W)|
45  // max = (Dot(N,C)-d) + r*sqrt(1-Dot(N,W)^2) + (h/2)*|Dot(N,W)|
46  Real center = Dot(halfspace.normal, cylinder.axis.origin) -
47  halfspace.constant;
48  Real absNdW = std::abs(Dot(halfspace.normal, cylinder.axis.direction));
49  Real root = sqrt(std::max((Real)1, (Real)1 - absNdW * absNdW));
50  Real tmax = center + cylinder.radius*root +
51  ((Real)0.5)*cylinder.height*absNdW;
52 
53  // The cylinder and halfspace intersect when the projection interval
54  // maximum is nonnegative.
55  result.intersect = (tmax >= (Real)0);
56  return result;
57 }
58 
59 
60 }
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