GteContCircle2.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 
10 #include <Mathematics/GteVector2.h>
12 
13 namespace gte
14 {
15 
16 // Compute the smallest circle whose center is the average of the input
17 // points.
18 template <typename Real>
19 bool GetContainer(int numPoints, Vector2<Real> const* points,
20  Circle2<Real>& circle);
21 
22 // Test for containment of a point inside a circle.
23 template <typename Real>
24 bool InContainer(Vector2<Real> const& point, Circle2<Real> const& circle);
25 
26 // Compute the smallest circle that contains the input circles.
27 template <typename Real>
28 bool MergeContainers(Circle2<Real> const& circle0,
29  Circle2<Real> const& circle1, Circle2<Real>& merge);
30 
31 
32 template <typename Real>
33 bool GetContainer(int numPoints, Vector2<Real> const* points,
34  Circle2<Real>& circle)
35 {
36  circle.center = points[0];
37  for (int i = 1; i < numPoints; ++i)
38  {
39  circle.center += points[i];
40  }
41  circle.center /= (Real)numPoints;
42 
43  for (int i = 0; i < numPoints; ++i)
44  {
45  Vector2<Real> diff = points[i] - circle.center;
46  Real radiusSqr = Dot(diff, diff);
47  if (radiusSqr > circle.radius)
48  {
49  circle.radius = radiusSqr;
50  }
51  }
52 
53  circle.radius = sqrt(circle.radius);
54  return true;
55 }
56 
57 template <typename Real>
58 bool InContainer(Vector2<Real> const& point, Circle2<Real> const& circle)
59 {
60  Vector2<Real> diff = point - circle.center;
61  return Length(diff) <= circle.radius;
62 }
63 
64 template <typename Real>
65 bool MergeContainers(Circle2<Real> const& circle0,
66  Circle2<Real> const& circle1, Circle2<Real>& merge)
67 {
68  Vector2<Real> cenDiff = circle1.center - circle0.center;
69  Real lenSqr = Dot(cenDiff, cenDiff);
70  Real rDiff = circle1.radius - circle0.radius;
71  Real rDiffSqr = rDiff*rDiff;
72 
73  if (rDiffSqr >= lenSqr)
74  {
75  merge = (rDiff >= (Real)0 ? circle1 : circle0);
76  }
77  else
78  {
79  Real length = sqrt(lenSqr);
80  if (length > (Real)0)
81  {
82  Real coeff = (length + rDiff) / (((Real)2)*length);
83  merge.center = circle0.center + coeff*cenDiff;
84  }
85  else
86  {
87  merge.center = circle0.center;
88  }
89 
90  merge.radius = ((Real)0.5)*(length + circle0.radius + circle1.radius);
91  }
92 
93  return true;
94 }
95 
96 
97 }
bool GetContainer(int numPoints, Vector3< Real > const *points, Capsule3< Real > &capsule)
bool MergeContainers(Capsule3< Real > const &capsule0, Capsule3< Real > const &capsule1, Capsule3< Real > &merge)
bool InContainer(Vector3< Real > const &point, Capsule3< Real > const &capsule)
GLfixed GLfixed GLint GLint GLfixed points
Definition: glext.h:4927
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:790
DualQuaternion< Real > Length(DualQuaternion< Real > const &d, bool robust=false)
Vector< N, Real > center


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59