Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/csg/gencyl.cpp
3206 views
1
#include <linalg.hpp>
2
#include <csg.hpp>
3
4
5
namespace netgen
6
{
7
8
GeneralizedCylinder :: GeneralizedCylinder (ExplicitCurve2d & acrosssection,
9
Point<3> ap, Vec<3> ae1, Vec<3> ae2)
10
: crosssection(acrosssection)
11
{
12
planep = ap;
13
planee1 = ae1;
14
planee2 = ae2;
15
planee3 = Cross (planee1, planee2);
16
(*testout) << "Vecs = " << planee1 << " " << planee2 << " " << planee3 << endl;
17
};
18
19
20
void GeneralizedCylinder :: Project (Point<3> & p) const
21
{
22
Point<2> p2d;
23
double z;
24
25
p2d = Point<2> (planee1 * (p - planep), planee2 * (p - planep));
26
z = planee3 * (p - planep);
27
28
crosssection.Project (p2d);
29
30
p = planep + p2d(0) * planee1 + p2d(1) * planee2 + z * planee3;
31
}
32
33
int GeneralizedCylinder ::BoxInSolid (const BoxSphere<3> & box) const
34
{
35
Point<3> p3d;
36
Point<2> p2d, projp;
37
double t;
38
Vec<2> tan, n;
39
40
p3d = box.Center();
41
42
p2d = Point<2> (planee1 * (p3d - planep), planee2 * (p3d - planep));
43
t = crosssection.ProjectParam (p2d);
44
45
projp = crosssection.Eval (t);
46
tan = crosssection.EvalPrime (t);
47
n(0) = tan(1);
48
n(1) = -tan(0);
49
50
if (Dist (p2d, projp) < box.Diam()/2)
51
return 2;
52
53
if (n * (p2d - projp) > 0)
54
{
55
return 0;
56
}
57
58
return 1;
59
}
60
61
double GeneralizedCylinder :: CalcFunctionValue (const Point<3> & point) const
62
{
63
Point<2> p2d, projp;
64
double t;
65
Vec<2> tan, n;
66
67
68
p2d = Point<2> (planee1 * (point - planep), planee2 * (point - planep));
69
t = crosssection.ProjectParam (p2d);
70
71
projp = crosssection.Eval (t);
72
tan = crosssection.EvalPrime (t);
73
n(0) = tan(1);
74
n(1) = -tan(0);
75
76
n /= n.Length();
77
return n * (p2d - projp);
78
}
79
80
void GeneralizedCylinder :: CalcGradient (const Point<3> & point, Vec<3> & grad) const
81
{
82
Point<2> p2d, projp;
83
double t;
84
Vec<2> tan, n;
85
86
87
p2d = Point<2> (planee1 * (point - planep), planee2 * (point - planep));
88
t = crosssection.ProjectParam (p2d);
89
90
projp = crosssection.Eval (t);
91
tan = crosssection.EvalPrime (t);
92
n(0) = tan(1);
93
n(1) = -tan(0);
94
95
n /= n.Length();
96
grad = n(0) * planee1 + n(1) * planee2;
97
}
98
99
100
void GeneralizedCylinder :: CalcHesse (const Point<3> & point, Mat<3> & hesse) const
101
{
102
Point<2> p2d, projp;
103
double t, dist, val;
104
Point<2> curvp;
105
Vec<2> curvpp;
106
Mat<2> h2d;
107
Mat<3,2> vmat;
108
int i, j, k, l;
109
110
p2d = Point<2> (planee1 * (point - planep), planee2 * (point - planep));
111
t = crosssection.ProjectParam (p2d);
112
113
curvp = crosssection.CurvCircle (t);
114
curvpp = p2d-curvp;
115
dist = curvpp.Length();
116
curvpp /= dist;
117
118
h2d(1, 1) = (1 - curvpp(0) * curvpp(0) ) / dist;
119
h2d(1, 2) = h2d(2, 1) = (- curvpp(0) * curvpp(1) ) / dist;
120
h2d(2, 2) = (1 - curvpp(1) * curvpp(1) ) / dist;
121
122
vmat(0,0) = planee1(0);
123
vmat(1,0) = planee1(1);
124
vmat(2,0) = planee1(2);
125
vmat(0,1) = planee2(0);
126
vmat(1,1) = planee2(1);
127
vmat(2,1) = planee2(2);
128
129
for (i = 0; i < 3; i++)
130
for (j = 0; j < 3; j++)
131
{
132
val = 0;
133
for (k = 0; k < 2; k++)
134
for (l = 0; l < 2; l++)
135
val += vmat(i,k) * h2d(k,l) * vmat(j,l);
136
hesse(i,j) = val;
137
}
138
}
139
140
141
double GeneralizedCylinder :: HesseNorm () const
142
{
143
return crosssection.MaxCurvature();
144
}
145
146
double GeneralizedCylinder :: MaxCurvatureLoc (const Point<3> & c, double rad) const
147
{
148
Point<2> c2d = Point<2> (planee1 * (c - planep), planee2 * (c - planep));
149
return crosssection.MaxCurvatureLoc(c2d, rad);
150
}
151
152
153
154
Point<3> GeneralizedCylinder :: GetSurfacePoint () const
155
{
156
Point<2> p2d;
157
p2d = crosssection.Eval(0);
158
return planep + p2d(0) * planee1 + p2d(1) * planee2;
159
}
160
161
void GeneralizedCylinder :: Reduce (const BoxSphere<3> & box)
162
{
163
Point<2> c2d = Point<2> (planee1 * (box.Center() - planep),
164
planee2 * (box.Center() - planep));
165
crosssection.Reduce (c2d, box.Diam()/2);
166
}
167
168
void GeneralizedCylinder :: UnReduce ()
169
{
170
crosssection.UnReduce ();
171
}
172
173
void GeneralizedCylinder :: Print (ostream & str) const
174
{
175
str << "Generalized Cylinder" << endl;
176
crosssection.Print (str);
177
}
178
179
#ifdef MYGRAPH
180
void GeneralizedCylinder :: Plot (const class ROT3D & rot) const
181
{
182
Point<2> p2d;
183
Point<3> p, oldp;
184
double t, tmin, tmax, dt;
185
186
tmin = crosssection.MinParam();
187
tmax = crosssection.MaxParam();
188
dt = (tmax - tmin)/ 500;
189
190
p2d = crosssection.Eval(tmin);
191
p = planep + p2d(0) * planee1 + p2d(1) * planee2;
192
193
for (t = tmin; t <= tmax+dt; t += dt)
194
{
195
if (crosssection.SectionUsed (t))
196
MySetColor (RED);
197
else
198
MySetColor (BLUE);
199
200
oldp = p;
201
p2d = crosssection.Eval(t);
202
p = planep + p2d(0) * planee1 + p2d(1) * planee2;
203
MyLine3D (p, oldp, rot);
204
}
205
206
}
207
208
#endif
209
}
210
211