GteDistRay3Rectangle3.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/GteRay.h>
13 
14 namespace gte
15 {
16 
17 template <typename Real>
18 class DCPQuery<Real, Ray3<Real>, Rectangle3<Real>>
19 {
20 public:
21  struct Result
22  {
24  Real rayParameter, rectangleParameter[2];
25  Vector3<Real> closestPoint[2];
26  };
27 
28  Result operator()(Ray3<Real> const& ray,
29  Rectangle3<Real> const& rectangle);
30 };
31 
32 
33 template <typename Real>
36  Ray3<Real> const& ray, Rectangle3<Real> const& rectangle)
37 {
38  Result result;
39 
40  Line3<Real> line(ray.origin, ray.direction);
42  auto lrResult = lrQuery(line, rectangle);
43 
44  if (lrResult.lineParameter >= (Real)0)
45  {
46  result.distance = lrResult.distance;
47  result.sqrDistance = lrResult.sqrDistance;
48  result.rayParameter = lrResult.lineParameter;
49  result.rectangleParameter[0] = lrResult.rectangleParameter[0];
50  result.rectangleParameter[1] = lrResult.rectangleParameter[1];
51  result.closestPoint[0] = lrResult.closestPoint[0];
52  result.closestPoint[1] = lrResult.closestPoint[1];
53  }
54  else
55  {
57  auto prResult = prQuery(ray.origin, rectangle);
58  result.distance = prResult.distance;
59  result.sqrDistance = prResult.sqrDistance;
60  result.rayParameter = (Real)0;
61  result.rectangleParameter[0] = prResult.rectangleParameter[0];
62  result.rectangleParameter[1] = prResult.rectangleParameter[1];
63  result.closestPoint[0] = ray.origin;
64  result.closestPoint[1] = prResult.rectangleClosestPoint;
65  }
66  return result;
67 }
68 
69 
70 }
GLsizei GLsizei GLfloat distance
Definition: glext.h:9704
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 03:59:59