GteIntrOrientedBox3Sphere3.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 namespace gte
14 {
15 
16 template <typename Real>
17 class TIQuery<Real, OrientedBox3<Real>, Sphere3<Real>>
18  :
19  public TIQuery<Real, AlignedBox3<Real>, Sphere3<Real>>
20 {
21 public:
22  // The intersection query considers the box and sphere to be solids.
23  // For example, if the sphere is strictly inside the box (does not touch
24  // the box faces), the objects intersect.
25  struct Result
26  :
27  public TIQuery<Real, AlignedBox3<Real>, Sphere3<Real>>::Result
28  {
29  // No additional information to compute.
30  };
31 
32  Result operator()(OrientedBox3<Real> const& box, Sphere3<Real> const& sphere);
33 };
34 
35 template <typename Real>
36 class FIQuery<Real, OrientedBox3<Real>, Sphere3<Real>>
37  :
38  public FIQuery<Real, AlignedBox3<Real>, Sphere3<Real>>
39 {
40 public:
41  // Currently, only a dynamic query is supported. The static query must
42  // compute the intersection set of (solid) box and sphere.
43  struct Result
44  :
45  public FIQuery<Real, AlignedBox3<Real>, Sphere3<Real>>::Result
46  {
47  // No additional information to compute.
48  };
49 
50  Result operator()(Real maxTime, OrientedBox3<Real> const& box,
51  Vector3<Real> const& boxVelocity, Sphere3<Real> const& sphere,
52  Vector3<Real> const& sphereVelocity);
53 };
54 
55 
56 template <typename Real>
59  OrientedBox3<Real> const& box, Sphere3<Real> const& sphere)
60 {
61  // Test for intersection in the coordinate system of the box by
62  // transforming the sphere into that coordinate system.
63  Vector3<Real> temp = sphere.center - box.center;
64  Vector3<Real> cdiff{ Dot(temp, box.axis[0]), Dot(temp, box.axis[1]), Dot(temp, box.axis[2]) };
65 
66  Result result;
67  this->DoQuery(box.extent, cdiff, sphere.radius, result);
68  return result;
69 }
70 
71 
72 template <typename Real>
75  OrientedBox3<Real> const& box, Vector3<Real> const& boxVelocity,
76  Sphere3<Real> const& sphere, Vector3<Real> const& sphereVelocity)
77 {
78  // Find intersections relative to the coordinate system of the box.
79  // The sphere is transformed to the box coordinates and the velocity of
80  // the sphere is relative to the box.
81  Vector3<Real> temp = sphere.center - box.center;
82  Vector3<Real> cdiff{ Dot(temp, box.axis[0]), Dot(temp, box.axis[1]), Dot(temp, box.axis[2]) };
83  temp = sphereVelocity - boxVelocity;
84  Vector3<Real> relvel{ Dot(temp, box.axis[0]), Dot(temp, box.axis[1]), Dot(temp, box.axis[2]) };
85 
86  Result result;
87  this->DoQuery(maxTime, box.center, box.extent, sphere, cdiff, relvel, result);
88  return result;
89 }
90 
91 }
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