GteDarbouxFrame.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 
11 #include <Mathematics/GteVector3.h>
13 #include <memory>
14 
15 namespace gte
16 {
17 template <typename Real>
19 {
20 public:
21  // Construction. The curve must persist as long as the DarbouxFrame3
22  // object does.
23  DarbouxFrame3(std::shared_ptr<ParametricSurface<3, Real>> const& surface);
24 
25  // Get a coordinate frame, {T0, T1, N}. At a nondegenerate surface
26  // points, dX/du and dX/dv are linearly independent tangent vectors.
27  // The frame is constructed as
28  // T0 = (dX/du)/|dX/du|
29  // N = Cross(dX/du,dX/dv)/|Cross(dX/du,dX/dv)|
30  // T1 = Cross(N, T0)
31  // so that {T0, T1, N} is a right-handed orthonormal set.
32  void operator()(Real u, Real v, Vector3<Real>& position,
33  Vector3<Real>& tangent0, Vector3<Real>& tangent1, Vector3<Real>& normal) const;
34 
35  // Compute the principal curvatures and principal directions.
36  void GetPrincipalInformation(Real u, Real v, Real& curvature0, Real& curvature1,
37  Vector3<Real>& direction0, Vector3<Real>& direction1) const;
38 
39 private:
40  std::shared_ptr<ParametricSurface<3, Real>> mSurface;
41 };
42 
43 
44 template <typename Real>
46  std::shared_ptr<ParametricSurface<3, Real>> const& surface)
47  :
48  mSurface(surface)
49 {
50 }
51 
52 template <typename Real>
53 void DarbouxFrame3<Real>::operator()(Real u, Real v, Vector3<Real>& position,
54  Vector3<Real>& tangent0, Vector3<Real>& tangent1, Vector3<Real>& normal) const
55 {
57  mSurface->Evaluate(u, v, 1, values);
58  position = values[0];
59  tangent0 = values[1];
60  Normalize(tangent0);
61  tangent1 = values[2];
62  Normalize(tangent1);
63  normal = UnitCross(tangent0, tangent1);
64  tangent1 = Cross(normal, tangent0);
65 }
66 
67 template <typename Real>
68 void DarbouxFrame3<Real>::GetPrincipalInformation(Real u, Real v, Real& curvature0,
69  Real& curvature1, Vector3<Real>& direction0, Vector3<Real>& direction1) const
70 {
71  // Tangents: T0 = (x_u,y_u,z_u), T1 = (x_v,y_v,z_v)
72  // Normal: N = Cross(T0,T1)/Length(Cross(T0,T1))
73  // Metric Tensor: G = +- -+
74  // | Dot(T0,T0) Dot(T0,T1) |
75  // | Dot(T1,T0) Dot(T1,T1) |
76  // +- -+
77  //
78  // Curvature Tensor: B = +- -+
79  // | -Dot(N,T0_u) -Dot(N,T0_v) |
80  // | -Dot(N,T1_u) -Dot(N,T1_v) |
81  // +- -+
82  //
83  // Principal curvatures k are the generalized eigenvalues of
84  //
85  // Bw = kGw
86  //
87  // If k is a curvature and w=(a,b) is the corresponding solution to
88  // Bw = kGw, then the principal direction as a 3D vector is d = a*U+b*V.
89  //
90  // Let k1 and k2 be the principal curvatures. The mean curvature
91  // is (k1+k2)/2 and the Gaussian curvature is k1*k2.
92 
93  // Compute derivatives.
95  mSurface->Evaluate(u, v, 2, values);
96  Vector3<Real> derU = values[1];
97  Vector3<Real> derV = values[2];
98  Vector3<Real> derUU = values[3];
99  Vector3<Real> derUV = values[4];
100  Vector3<Real> derVV = values[5];
101 
102  // Compute the metric tensor.
103  Matrix2x2<Real> metricTensor;
104  metricTensor(0, 0) = Dot(values[1], values[1]);
105  metricTensor(0, 1) = Dot(values[1], values[2]);
106  metricTensor(1, 0) = metricTensor(0, 1);
107  metricTensor(1, 1) = Dot(values[2], values[2]);
108 
109  // Compute the curvature tensor.
110  Vector3<Real> normal = UnitCross(values[1], values[2]);
111  Matrix2x2<Real> curvatureTensor;
112  curvatureTensor(0, 0) = -Dot(normal, derUU);
113  curvatureTensor(0, 1) = -Dot(normal, derUV);
114  curvatureTensor(1, 0) = curvatureTensor(0, 1);
115  curvatureTensor(1, 1) = -Dot(normal, derVV);
116 
117  // Characteristic polynomial is 0 = det(B-kG) = c2*k^2+c1*k+c0.
118  Real c0 = Determinant(curvatureTensor);
119  Real c1 = ((Real)2) * curvatureTensor(0, 1) * metricTensor(0, 1) -
120  curvatureTensor(0, 0) * metricTensor(1, 1) -
121  curvatureTensor(1, 1) * metricTensor(0, 0);
122  Real c2 = Determinant(metricTensor);
123 
124  // Principal curvatures are roots of characteristic polynomial.
125  Real temp = sqrt(std::abs(c1 * c1 - ((Real)4) * c0 * c2));
126  Real mult = ((Real)0.5) / c2;
127  curvature0 = -mult * (c1 + temp);
128  curvature1 = -mult * (c1 - temp);
129 
130  // Principal directions are solutions to (B-kG)w = 0,
131  // w1 = (b12-k1*g12,-(b11-k1*g11)) OR (b22-k1*g22,-(b12-k1*g12)).
132  Real a0 = curvatureTensor(0, 1) - curvature0 * metricTensor(0, 1);
133  Real a1 = curvature0 * metricTensor(0, 0) - curvatureTensor(0, 0);
134  Real length = sqrt(a0 * a0 + a1 * a1);
135  if (length > (Real)0)
136  {
137  direction0 = a0 * derU + a1 * derV;
138  }
139  else
140  {
141  a0 = curvatureTensor(1, 1) - curvature0 * metricTensor(1, 1);
142  a1 = curvature0 * metricTensor(0, 1) - curvatureTensor(0, 1);
143  length = sqrt(a0 * a0 + a1 * a1);
144  if (length > (Real)0)
145  {
146  direction0 = a0*derU + a1*derV;
147  }
148  else
149  {
150  // Umbilic (surface is locally sphere, any direction principal).
151  direction0 = derU;
152  }
153  }
154  Normalize(direction0);
155 
156  // Second tangent is cross product of first tangent and normal.
157  direction1 = Cross(direction0, normal);
158 }
159 
160 }
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
Definition: GteBSNumber.h:966
void GetPrincipalInformation(Real u, Real v, Real &curvature0, Real &curvature1, Vector3< Real > &direction0, Vector3< Real > &direction1) const
Vector< N, Real > UnitCross(Vector< N, Real > const &v0, Vector< N, Real > const &v1, bool robust=false)
Definition: GteVector3.h:130
std::shared_ptr< ParametricSurface< 3, Real > > mSurface
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1597
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Real Normalize(GVector< Real > &v, bool robust=false)
Definition: GteGVector.h:454
DualQuaternion< Real > Cross(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:790
void operator()(Real u, Real v, Vector3< Real > &position, Vector3< Real > &tangent0, Vector3< Real > &tangent1, Vector3< Real > &normal) const
const GLdouble * v
Definition: glcorearb.h:832
DarbouxFrame3(std::shared_ptr< ParametricSurface< 3, Real >> const &surface)
Real Determinant(GMatrix< Real > const &M)
Definition: GteGMatrix.h:618


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