GteDistPoint3Circle3.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/GteCircle3.h>
13 
14 // The 3D point-circle distance algorithm is described in
15 // http://www.geometrictools.com/Documentation/DistanceToCircle3.pdf
16 // The notation used in the code matches that of the document.
17 
18 namespace gte
19 {
20 
21 template <typename Real>
22 class DCPQuery<Real, Vector3<Real>, Circle3<Real>>
23 {
24 public:
25  // Either a single point on the circle is closest to 'point', in which
26  // case 'equidistant' is false, or the entire circle is closest to
27  // 'point', in which case 'equidistant' is true. In the latter case, the
28  // query returns the circle point C+r*U, where C is the circle center, r
29  // is the circle radius, and U is a vector perpendicular to the normal N
30  // for the plane of the circle.
31  struct Result
32  {
36  };
37 
38  Result operator()(Vector3<Real> const& point,
39  Circle3<Real> const& circle);
40 };
41 
42 
43 template <typename Real>
46  Vector3<Real> const& point, Circle3<Real> const& circle)
47 {
48  Result result;
49 
50  // Projection of P-C onto plane is Q-C = P-C - Dot(N,P-C)*N.
51  Vector3<Real> PmC = point - circle.center;
52  Vector3<Real> QmC = PmC - Dot(circle.normal, PmC)*circle.normal;
53  Real lengthQmC = Length(QmC);
54  if (lengthQmC > (Real)0)
55  {
56  result.circleClosest =
57  circle.center + (circle.radius / lengthQmC) * QmC;
58  result.equidistant = false;
59  }
60  else
61  {
62  // All circle points are equidistant from P. Return one of them.
63  Vector3<Real> basis[3];
64  basis[0] = circle.normal;
66  result.circleClosest = circle.center + circle.radius * basis[1];
67  result.equidistant = true;
68  }
69 
70  Vector3<Real> diff = point - result.circleClosest;
71  result.sqrDistance = Dot(diff, diff);
72  result.distance = Function<Real>::Sqrt(result.sqrDistance);
73  return result;
74 }
75 
76 
77 }
GLsizei GLsizei GLfloat distance
Definition: glext.h:9704
static Real Sqrt(Real const &x)
Definition: GteFunctions.h:937
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
DualQuaternion< Real > Length(DualQuaternion< Real > const &d, bool robust=false)
Real ComputeOrthogonalComplement(int numInputs, Vector2< Real > *v, bool robust=false)
Definition: GteVector2.h:123
GLuint64EXT * result
Definition: glext.h:10003


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