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