GteProjection.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/GteLine.h>
12 
13 namespace gte
14 {
15 
16 // Project an ellipse onto a line. The projection interval is [smin,smax]
17 // and corresponds to the line segment P+s*D, where smin <= s <= smax.
18 template <typename Real>
19 void Project(Ellipse2<Real> const& ellipse, Line2<Real> const& line,
20  Real& smin, Real& smax);
21 
22 // Project an ellipsoid onto a line. The projection interval is [smin,smax]
23 // and corresponds to the line segment P+s*D, where smin <= s <= smax.
24 template <typename Real>
25 void Project(Ellipsoid3<Real> const& ellipsoid,
26  Line3<Real> const& line, Real& smin, Real& smax);
27 
28 
29 template <typename Real>
30 void Project(Ellipse2<Real> const& ellipse, Line2<Real> const& line,
31  Real& smin, Real& smax)
32 {
33  // Center of projection interval.
34  Real center = Dot(line.direction, ellipse.center - line.origin);
35 
36  // Radius of projection interval.
37  Real tmp[2] =
38  {
39  ellipse.extent[0] * Dot(line.direction, ellipse.axis[0]),
40  ellipse.extent[1] * Dot(line.direction, ellipse.axis[1])
41  };
42  Real rSqr = tmp[0] * tmp[0] + tmp[1] * tmp[1];
43  Real radius = sqrt(rSqr);
44 
45  smin = center - radius;
46  smax = center + radius;
47 }
48 
49 template <typename Real>
50 void Project(Ellipsoid3<Real> const& ellipsoid, Line3<Real> const& line,
51  Real& smin, Real& smax)
52 {
53  // Center of projection interval.
54  Real center = Dot(line.direction, ellipsoid.center - line.origin);
55 
56  // Radius of projection interval.
57  Real tmp[3] =
58  {
59  ellipsoid.extent[0] * Dot(line.direction, ellipsoid.axis[0]),
60  ellipsoid.extent[1] * Dot(line.direction, ellipsoid.axis[1]),
61  ellipsoid.extent[2] * Dot(line.direction, ellipsoid.axis[2])
62  };
63  Real rSqr = tmp[0] * tmp[0] + tmp[1] * tmp[1] + tmp[2] * tmp[2];
64  Real radius = sqrt(rSqr);
65 
66  smin = center - radius;
67  smax = center + radius;
68 }
69 
70 
71 }
GVector< Real > Project(GVector< Real > const &v, int reject)
Definition: GteGVector.h:625
Vector< N, Real > extent
Vector< N, Real > direction
Definition: GteLine.h:29
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Vector< N, Real > origin
Definition: GteLine.h:29
Vector< N, Real > center
std::array< Vector< N, Real >, N > axis


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01