GteDistPointRay.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/GteRay.h>
12 
13 namespace gte
14 {
15 
16 template <int N, typename Real>
17 class DCPQuery<Real, Vector<N, Real>, Ray<N, Real>>
18 {
19 public:
20  struct Result
21  {
23  Real rayParameter; // t in [0,+infinity)
24  Vector<N, Real> rayClosest; // origin + t * direction
25  };
26 
27  Result operator()(Vector<N, Real> const& point, Ray<N, Real> const& ray);
28 };
29 
30 // Template aliases for convenience.
31 template <int N, typename Real>
32 using DCPPointRay =
34 
35 template <typename Real>
37 
38 template <typename Real>
40 
41 
42 template <int N, typename Real>
43 typename DCPQuery<Real, Vector<N, Real>, Ray<N, Real>>::Result
44 DCPQuery<Real, Vector<N, Real>, Ray<N, Real>>::operator()(
45  Vector<N, Real> const& point, Ray<N, Real> const& ray)
46 {
47  Result result;
48 
49  Vector<N, Real> diff = point - ray.origin;
50  result.rayParameter = Dot(ray.direction, diff);
51  if (result.rayParameter > (Real)0)
52  {
53  result.rayClosest = ray.origin + result.rayParameter*ray.direction;
54  }
55  else
56  {
57  result.rayClosest = ray.origin;
58  }
59 
60  diff = point - result.rayClosest;
61  result.sqrDistance = Dot(diff, diff);
62  result.distance = sqrt(result.sqrDistance);
63 
64  return result;
65 }
66 
67 
68 }
GLsizei GLsizei GLfloat distance
Definition: glext.h:9704
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLuint64EXT * result
Definition: glext.h:10003


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