GteFrenetFrame.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.1 (2016/06/29)
7 
8 #pragma once
9 
10 #include <Mathematics/GteVector2.h>
11 #include <Mathematics/GteVector3.h>
13 #include <memory>
14 
15 namespace gte
16 {
17 
18 template <typename Real>
20 {
21 public:
22  // Construction. The curve must persist as long as the FrenetFrame2
23  // object does.
24  FrenetFrame2(std::shared_ptr<ParametricCurve<2, Real>> const& curve);
25 
26  // The normal is perpendicular to the tangent, rotated clockwise by
27  // pi/2 radians.
28  void operator()(Real t, Vector2<Real>& position, Vector2<Real>& tangent,
29  Vector2<Real>& normal) const;
30 
31  Real GetCurvature(Real t) const;
32 
33 private:
34  std::shared_ptr<ParametricCurve<2, Real>> mCurve;
35 };
36 
37 
38 template <typename Real>
40 {
41 public:
42  // Construction. The curve must persist as long as the FrenetFrame3
43  // object does.
44  FrenetFrame3(std::shared_ptr<ParametricCurve<3, Real>> const& curve);
45 
46  // The binormal is Cross(tangent, normal).
47  void operator()(Real t, Vector3<Real>& position, Vector3<Real>& tangent,
48  Vector3<Real>& normal, Vector3<Real>& binormal) const;
49 
50  Real GetCurvature(Real t) const;
51  Real GetTorsion(Real t) const;
52 
53 private:
54  std::shared_ptr<ParametricCurve<3, Real>> mCurve;
55 };
56 
57 
58 template <typename Real>
60  :
61  mCurve(curve)
62 {
63 }
64 
65 template <typename Real>
67  Vector2<Real>& tangent, Vector2<Real>& normal) const
68 {
70  mCurve->Evaluate(t, 1, values);
71  position = values[0];
72  tangent = values[1];
73  Normalize(tangent);
74  normal = Perp(tangent);
75 }
76 
77 template <typename Real>
79 {
81  mCurve->Evaluate(t, 2, values);
82  Real speedSqr = Dot(values[1], values[1]);
83  if (speedSqr > (Real)0)
84  {
85  Real numer = DotPerp(values[1], values[2]);
86  Real denom = pow(speedSqr, (Real)1.5);
87  return numer / denom;
88  }
89  else
90  {
91  // Curvature is indeterminate, just return 0.
92  return (Real)0;
93  }
94 }
95 
96 
97 
98 template <typename Real>
100  :
101  mCurve(curve)
102 {
103 }
104 
105 template <typename Real>
107  Vector3<Real>& tangent, Vector3<Real>& normal, Vector3<Real>& binormal) const
108 {
110  mCurve->Evaluate(t, 2, values);
111  position = values[0];
112  Real VDotV = Dot(values[1], values[1]);
113  Real VDotA = Dot(values[1], values[2]);
114  normal = VDotV * values[2] - VDotA * values[1];
115  Normalize(normal);
116  tangent = values[1];
117  Normalize(tangent);
118  binormal = Cross(tangent, normal);
119 }
120 
121 template <typename Real>
123 {
125  mCurve->Evaluate(t, 2, values);
126  Real speedSqr = Dot(values[1], values[1]);
127  if (speedSqr > (Real)0)
128  {
129  Real numer = Length(Cross(values[1], values[2]));
130  Real denom = pow(speedSqr, (Real)1.5);
131  return numer / denom;
132  }
133  else
134  {
135  // Curvature is indeterminate, just return 0.
136  return (Real)0;
137  }
138 }
139 
140 template <typename Real>
142 {
144  mCurve->Evaluate(t, 3, values);
145  Vector3<Real> cross = Cross(values[1], values[2]);
146  Real denom = Dot(cross, cross);
147  if (denom > (Real)0)
148  {
149  Real numer = Dot(cross, values[3]);
150  return numer / denom;
151  }
152  else
153  {
154  // Torsion is indeterminate, just return 0.
155  return (Real)0;
156  }
157 }
158 
159 }
Real GetTorsion(Real t) const
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1597
std::shared_ptr< ParametricCurve< 3, Real > > mCurve
Real GetCurvature(Real t) const
Real DotPerp(Vector2< Real > const &v0, Vector2< Real > const &v1)
Definition: GteVector2.h:117
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Real Normalize(GVector< Real > &v, bool robust=false)
Definition: GteGVector.h:454
FrenetFrame2(std::shared_ptr< ParametricCurve< 2, Real >> const &curve)
GLdouble GLdouble t
Definition: glext.h:239
DualQuaternion< Real > Cross(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Vector2< Real > Perp(Vector2< Real > const &v)
Definition: GteVector2.h:103
DualQuaternion< Real > Length(DualQuaternion< Real > const &d, bool robust=false)
std::shared_ptr< ParametricCurve< 2, Real > > mCurve
void operator()(Real t, Vector2< Real > &position, Vector2< Real > &tangent, Vector2< Real > &normal) const
FrenetFrame3(std::shared_ptr< ParametricCurve< 3, Real >> const &curve)
void operator()(Real t, Vector3< Real > &position, Vector3< Real > &tangent, Vector3< Real > &normal, Vector3< Real > &binormal) const
Real GetCurvature(Real t) const


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