GteIntrPlane3Sphere3.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 
11 #include <Mathematics/GteCircle3.h>
13 #include <Mathematics/GteFIQuery.h>
14 #include <Mathematics/GteTIQuery.h>
15 
16 namespace gte
17 {
18 
19 template <typename Real>
20 class TIQuery<Real, Plane3<Real>, Sphere3<Real>>
21 {
22 public:
23  struct Result
24  {
25  bool intersect;
26  };
27 
28  Result operator()(Plane3<Real> const& plane, Sphere3<Real> const& sphere);
29 };
30 
31 template <typename Real>
32 class FIQuery<Real, Plane3<Real>, Sphere3<Real>>
33 {
34 public:
35  struct Result
36  {
37  bool intersect;
38 
39  // If 'intersect' is true, the intersection is either a point or a
40  // circle. When 'isCircle' is true, 'circle' is valid. When
41  // 'isCircle' is false, 'point' is valid.
42  bool isCircle;
45  };
46 
47  Result operator()(Plane3<Real> const& plane, Sphere3<Real> const& sphere);
48 };
49 
50 
51 template <typename Real>
54  Plane3<Real> const& plane, Sphere3<Real> const& sphere)
55 {
56  Result result;
58  auto ppResult = ppQuery(sphere.center, plane);
59  result.intersect = (ppResult.distance <= sphere.radius);
60  return result;
61 }
62 
63 
64 template <typename Real>
67  Plane3<Real> const& plane, Sphere3<Real> const& sphere)
68 {
69  Result result;
71  auto ppResult = ppQuery(sphere.center, plane);
72  if (ppResult.distance < sphere.radius)
73  {
74  result.intersect = true;
75  result.isCircle = true;
76  result.circle.center = sphere.center - ppResult.signedDistance * plane.normal;
77  result.circle.normal = plane.normal;
78  Real sum = sphere.radius + ppResult.distance; // > 0
79  Real dif = sphere.radius - ppResult.distance; // > 0
80  Real arg = sum * dif; // sqr(sphere.radius) - sqr(ppResult.distance)
81  result.circle.radius = sqrt(arg);
82  return result;
83  }
84  else if (ppResult.distance == sphere.radius)
85  {
86  result.intersect = true;
87  result.isCircle = false;
88  result.point = sphere.center - ppResult.signedDistance * plane.normal;
89  return result;
90  }
91  else
92  {
93  result.intersect = false;
94  return result;
95  }
96 }
97 
98 }
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