VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GbSystem3D.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#include <GbCuboid3D.h>
35#include <GbPolygon3D.h>
36#include <GbSystem3D.h>
37
38using namespace std;
39
41{
42 double dx1 = p11.x1 - p12.x1;
43 double dx2 = p11.x2 - p12.x2;
44 double dx3 = p11.x3 - p12.x3;
45 return std::sqrt(dx1 * dx1 + dx2 * dx2 + dx3 * dx3);
46}
47
49{
50 if (ub_math::less2(p11.x1, p12.x1, p21.x1, p22.x1))
51 return NULL;
52 if (ub_math::less2(p11.x2, p12.x2, p21.x2, p22.x2))
53 return NULL;
54 if (ub_math::less2(p11.x3, p12.x3, p21.x3, p22.x3))
55 return NULL;
56 if (ub_math::greater2(p11.x1, p12.x1, p21.x1, p22.x1))
57 return NULL;
58 if (ub_math::greater2(p11.x2, p12.x2, p21.x2, p22.x2))
59 return NULL;
60 if (ub_math::greater2(p11.x3, p12.x3, p21.x3, p22.x3))
61 return NULL;
62
63 double a11 = p12.x1 - p11.x1; //..HOW PARAMETERS ARE USED.........
64 double a12 = p12.x2 - p11.x2; //
65 double a13 = p12.x3 - p11.x3; // p11 and p12 represent line 1
66 double a21 = p21.x1 - p22.x1; // p21 and p22 represent line 2
67 double a22 = p21.x2 - p22.x2; //
68 double a23 = p21.x3 - p22.x3; //..................................
69 double b1 = p21.x1 - p11.x1;
70 double b2 = p21.x2 - p11.x2;
71 double b3 = p21.x3 - p11.x3;
72 double d1 = a11 * a22 - a12 * a21;
73 double d2 = a11 * a23 - a13 * a21;
74 double d3 = a12 * a23 - a13 * a22;
75 double t;
76
78 return NULL;
79 if (ub_math::zero(d1)) {
80 if (!ub_math::zero(d2))
81 t = (a23 * b1 - a21 * b3) / d2;
82 else
83 t = (a23 * b2 - a22 * b3) / d3;
84 } else if (ub_math::zero(d2)) {
85 if (!ub_math::zero(d1))
86 t = (a22 * b1 - a21 * b2) / d1;
87 else
88 t = (a23 * b2 - a22 * b3) / d3;
89 } else if (ub_math::zero(d3)) {
90 if (!ub_math::zero(d1))
91 t = (a22 * b1 - a21 * b2) / d1;
92 else
93 t = (a23 * b1 - a21 * b3) / d2;
94 } else
95 return NULL;
96
97 double x1 = p11.x1 + t * a11;
98 double x2 = p11.x2 + t * a12;
99 double x3 = p11.x3 + t * a13;
100
101 if (ub_math::inClosedInterval(x1, p11.x1, p12.x1) && ub_math::inClosedInterval(x1, p21.x1, p22.x1) &&
104 return new GbPoint3D(x1, x2, x3);
105
106 return NULL;
107}
108/*=================================================================*/
109// Line1: p11 -> p12 and Line2: p21 -> p22
111{
112 if (ub_math::less2(p11.x1, p12.x1, p21.x1, p22.x1))
113 return false;
114 if (ub_math::less2(p11.x2, p12.x2, p21.x2, p22.x2))
115 return false;
116 if (ub_math::less2(p11.x3, p12.x3, p21.x3, p22.x3))
117 return false;
118 if (ub_math::greater2(p11.x1, p12.x1, p21.x1, p22.x1))
119 return false;
120 if (ub_math::greater2(p11.x2, p12.x2, p21.x2, p22.x2))
121 return false;
122 if (ub_math::greater2(p11.x3, p12.x3, p21.x3, p22.x3))
123 return false;
124
125 double a11 = p12.x1 - p11.x1; //..HOW PARAMETERS ARE USED.........
126 double a12 = p12.x2 - p11.x2; //
127 double a13 = p12.x3 - p11.x3; // p11 and p12 represent line 1
128 double a21 = p21.x1 - p22.x1; // p21 and p22 represent line 2
129 double a22 = p21.x2 - p22.x2; //
130 double a23 = p21.x3 - p22.x3; //..................................
131 double b1 = p21.x1 - p11.x1;
132 double b2 = p21.x2 - p11.x2;
133 double b3 = p21.x3 - p11.x3;
134 double d1 = a11 * a22 - a12 * a21;
135 double d2 = a11 * a23 - a13 * a21;
136 double d3 = a12 * a23 - a13 * a22;
137 double t;
138
140 return false;
141 if (ub_math::zero(d1)) {
142 if (!ub_math::zero(d2))
143 t = (a23 * b1 - a21 * b3) / d2;
144 else
145 t = (a23 * b2 - a22 * b3) / d3;
146 } else if (ub_math::zero(d2)) {
147 if (!ub_math::zero(d1))
148 t = (a22 * b1 - a21 * b2) / d1;
149 else
150 t = (a23 * b2 - a22 * b3) / d3;
151 } else if (ub_math::zero(d3)) {
152 if (!ub_math::zero(d1))
153 t = (a22 * b1 - a21 * b2) / d1;
154 else
155 t = (a23 * b1 - a21 * b3) / d2;
156 } else
157 return false;
158
159 double x1 = p11.x1 + t * a11;
160 double x2 = p11.x2 + t * a12;
161 double x3 = p11.x3 + t * a13;
162
163 if (ub_math::inClosedInterval(x1, p11.x1, p12.x1) && ub_math::inClosedInterval(x1, p21.x1, p22.x1) &&
166 return true;
167 return false;
168}
169/*======================================================================*/
170//
171//
172// /*======================================================================*/
173// /* Private Methoden (Parallelism) */
174// /* */
176{
177 double a11 = p12.x1 - p11.x1; //..HOW PARAMETERS ARE USED.........
178 double a12 = p12.x2 - p11.x2; //
179 double a13 = p12.x3 - p11.x3; // p11 and p12 represent line 1
180 double a21 = p21.x1 - p22.x1; // p21 and p22 represent line 2
181 double a22 = p21.x2 - p22.x2; //
182 double a23 = p21.x3 - p22.x3; //..................................
183
184 return (ub_math::zero(a11 * a22 - a12 * a21) && ub_math::zero(a11 * a23 - a13 * a21) &&
185 ub_math::zero(a12 * a23 - a13 * a22));
186}
187/*======================================================================*/
188
189/*======================================================================*/
190/* General Clipping Methods */
191//......................................................................*/
192//
193// Method Parameters Result Remarks
194// --------- --------------------------------------------- --------- -------------------
195// clip###2D (2D objects to be clipped, 2+2 clipping values) 2D object clipping x1, x2
196// clip###3D (3D objects to be clipped, 2+2 clipping values) 3D object clipping x1, x2
197// clip###3D (3D objects to be clipped, 3+3 clipping values) 3D object clipping x1, x2, x3
198// clip###3D (3D objects to be clipped, 1+1 clipping values) 3D object clipping x3
199//
200/*======================================================================*/
201/* Private Methoden (Clipping Lines) */
202/* */
203GbLine3D *gb_system_3d::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, double x2a, double x3a, double x1b,
204 double x2b, double x3b)
205{
206 GbPoint3D *p1 = new GbPoint3D(pA);
207 GbPoint3D *p2 = new GbPoint3D(pB);
208
209 if (ub_math::greater(x1a, x1b)) {
210 double x1 = x1a;
211 x1a = x1b;
212 x1b = x1;
213 }
214 if (ub_math::greater(x2a, x2b)) {
215 double x2 = x2a;
216 x2a = x2b;
217 x2b = x2;
218 }
219 if (ub_math::greater(x3a, x3b)) {
220 double x3 = x3a;
221 x3a = x3b;
222 x3b = x3;
223 }
224
225 double f;
226
227 /*-------------------------------------------------------------------*/
228 /* Schneiden an vorderer Kante */
229 /* */
230 if (ub_math::less(p1->x3, x3a)) {
231 if (ub_math::less(p2->x3, x3a)) {
232 delete p1;
233 delete p2;
234 return NULL;
235 }
236
237 f = (x3a - p1->x3) / (p1->x3 - p2->x3);
238 p1->x1 += (p1->x1 - p2->x1) * f;
239 p1->x2 += (p1->x2 - p2->x2) * f;
240 p1->x3 = x3a;
241 } else if (ub_math::less(p2->x3, x3a)) {
242 f = (x3a - p2->x3) / (p2->x3 - p1->x3);
243 p2->x1 += (p2->x1 - p1->x1) * f;
244 p2->x2 += (p2->x2 - p1->x2) * f;
245 p2->x3 = x3a;
246 }
247 /*-------------------------------------------------------------------*/
248 /* Schneiden an unterer Kante */
249 /* */
250 if (ub_math::less(p1->x2, x2a)) {
251 if (ub_math::less(p2->x2, x2a)) {
252 delete p1;
253 delete p2;
254 return NULL;
255 }
256
257 f = (x2a - p1->x2) / (p1->x2 - p2->x2);
258 p1->x1 += (p1->x1 - p2->x1) * f;
259 p1->x3 += (p1->x3 - p2->x3) * f;
260 p1->x2 = x2a;
261 } else if (ub_math::less(p2->x2, x2a)) {
262 f = (x2a - p2->x2) / (p2->x2 - p1->x2);
263 p2->x1 += (p2->x1 - p1->x1) * f;
264 p2->x3 += (p2->x3 - p1->x3) * f;
265 p2->x2 = x2a;
266 }
267 /*-------------------------------------------------------------------*/
268 /* Schneiden an rechter Kante */
269 /* */
270 if (ub_math::greater(p1->x1, x1b)) {
271 if (ub_math::greater(p2->x1, x1b)) {
272 delete p1;
273 delete p2;
274 return NULL;
275 }
276
277 f = (x1b - p1->x1) / (p1->x1 - p2->x1);
278 p1->x2 += (p1->x2 - p2->x2) * f;
279 p1->x3 += (p1->x3 - p2->x3) * f;
280 p1->x1 = x1b;
281 } else if (ub_math::greater(p2->x1, x1b)) {
282 f = (x1b - p2->x1) / (p2->x1 - p1->x1);
283 p2->x2 += (p2->x2 - p1->x2) * f;
284 p2->x3 += (p2->x3 - p1->x3) * f;
285 p2->x1 = x1b;
286 }
287 /*-------------------------------------------------------------------*/
288 /* Schneiden an hinterer Kante */
289 /* */
290 if (ub_math::greater(p1->x3, x3b)) {
291 if (ub_math::greater(p2->x3, x3b)) {
292 delete p1;
293 delete p2;
294 return NULL;
295 }
296
297 f = (x3b - p1->x3) / (p1->x3 - p2->x3);
298 p1->x1 += (p1->x1 - p2->x1) * f;
299 p1->x2 += (p1->x2 - p2->x2) * f;
300 p1->x3 = x3b;
301 } else if (ub_math::greater(p2->x3, x3b)) {
302 f = (x3b - p2->x3) / (p2->x3 - p1->x3);
303 p2->x1 += (p2->x1 - p1->x1) * f;
304 p2->x2 += (p2->x2 - p1->x2) * f;
305 p2->x3 = x3b;
306 }
307 /*-------------------------------------------------------------------*/
308 /* Schneiden an oberer Kante */
309 /* */
310 if (ub_math::greater(p1->x2, x2b)) {
311 if (ub_math::greater(p2->x2, x2b)) {
312 delete p1;
313 delete p2;
314 return NULL;
315 }
316
317 f = (x2b - p1->x2) / (p1->x2 - p2->x2);
318 p1->x1 += (p1->x1 - p2->x1) * f;
319 p1->x3 += (p1->x3 - p2->x3) * f;
320 p1->x2 = x2b;
321 } else if (ub_math::greater(p2->x2, x2b)) {
322 f = (x2b - p2->x2) / (p2->x2 - p1->x2);
323 p2->x1 += (p2->x1 - p1->x1) * f;
324 p2->x3 += (p2->x3 - p1->x3) * f;
325 p2->x2 = x2b;
326 }
327 /*-------------------------------------------------------------------*/
328 /* Schneiden an linker Kante */
329 /* */
330 if (ub_math::less(p1->x1, x1a)) {
331 if (ub_math::less(p2->x1, x1a)) {
332 delete p1;
333 delete p2;
334 return NULL;
335 }
336
337 f = (x1a - p1->x1) / (p1->x1 - p2->x1);
338 p1->x2 += (p1->x2 - p2->x2) * f;
339 p1->x3 += (p1->x3 - p2->x3) * f;
340 p1->x1 = x1a;
341 } else if (ub_math::less(p2->x1, x1a)) {
342 f = (x1a - p2->x1) / (p2->x1 - p1->x1);
343 p2->x2 += (p2->x2 - p1->x2) * f;
344 p2->x3 += (p2->x3 - p1->x3) * f;
345 p2->x1 = x1a;
346 }
347 /*-------------------------------------------------------------------*/
348 return new GbLine3D(p1, p2);
349}
350// /*======================================================================*/
351// /* Private Methoden (Clipping Rectangles) */
352// /* */
353// final static GbPolygon3D clipPolygon3D(GbPoint3D points[], double x11, double x12, double x21, double x22)
354// {
355// GbPoint3D last = null;
356// PointSet3 ps = new PointSet3(points);
357// boolean flag = false;
358// int n = points.length;
359// int i;
360// double f;
361//
362// if(n == 0) return(null);
363// if(greater(x11, x21)) { double ax = x11; x11 = x21; x21 = ax; }
364// if(greater(x12, x22)) { double ay = x12; x12 = x22; x22 = ay; }
365//
366// /*-------------------------------------------------------------------*/
367// /* Schneiden an unterer Kante */
368// /* */
369// if(less(ps.getX2Minimum(), x12))
370// {
371// ps.clear();
372// last = points[0];
373// if(less((*points)[0]->x2, x12)) flag = false;
374// else
375// {
376// ps.add(points[0]);
377// flag = true;
378// }
379// for(i=1; i<n; i++)
380// {
381// if(less((*points)[i]->x2, x12))
382// {
383// if(flag)
384// {
385// f = (x12-(*points)[i]->x2)/((*points)[i]->x2-last->x2);
386// ps.add(new GbPoint3D((*points)[i]->x1 + ((*points)[i]->x1-last->x1)*f, x12, (*points)[i]->x3 +
387//((*points)[i]->x3-last->x3)*f));
388// }
389// flag = false;
390// }
391// else
392// {
393// if(!flag)
394// {
395// f = (x12-(*points)[i]->x2)/((*points)[i]->x2-last->x2);
396// ps.add(new GbPoint3D((*points)[i]->x1 + ((*points)[i]->x1-last->x1)*f, x12, (*points)[i]->x3 +
397//((*points)[i]->x3-last->x3)*f));
398// }
399// ps.add((*points)[i]);
400// flag = true;
401// }
402// last = points[i];
403// }
404// if(!((less(points[0].x2, x12)) ^ flag))
405// {
406// f = (x12-points[0].x2)/(points[0].x2-last->x2);
407// ps.add(new GbPoint3D(points[0].x1 + (points[0].x1-last->x1)*f, x12, points[0].x3 + (points[0].x3-last->x3)*f));
408// }
409//
410// points = ps.getPoints();
411// n = points.length;
412//
413// if(n == 0) return(null);
414// }
415// /*-------------------------------------------------------------------*/
416// /* Schneiden an rechter Kante */
417// /* */
418// if(greater(ps.getX1Maximum(), x21))
419// {
420// ps.clear();
421// last = points[0];
422// if(greater(points[0].x1, x21)) flag = false;
423// else
424// {
425// ps.add(points[0]);
426// flag = true;
427// }
428// for(i=1; i<n; i++)
429// {
430// if(greater((*points)[i]->x1, x21))
431// {
432// if(flag)
433// {
434// f = (x21-(*points)[i]->x1)/((*points)[i]->x1-last->x1);
435// ps.add(new GbPoint3D(x21, (*points)[i]->x2 + ((*points)[i]->x2-last->x2)*f, (*points)[i]->x3 +
436//((*points)[i]->x3-last->x3)*f));
437// }
438// flag = false;
439// }
440// else
441// {
442// if(!flag)
443// {
444// f = (x21-(*points)[i]->x1)/((*points)[i]->x1-last->x1);
445// ps.add(new GbPoint3D(x21, (*points)[i]->x2 + ((*points)[i]->x2-last->x2)*f, (*points)[i]->x3 +
446//((*points)[i]->x3-last->x3)*f));
447// }
448// ps.add(points[i]);
449// flag = true;
450// }
451// last = points[i];
452// }
453// if(!((greater(points[0].x1, x21)) ^ flag))
454// {
455// f = (x21-points[0].x1)/(points[0].x1-last.x1);
456// ps.add(new GbPoint3D(x21, points[0].x2 + (points[0].x2-last.x2)*f, points[0].x3 + (points[0].x3-last.x3)*f));
457// }
458//
459// points = ps.getPoints();
460// n = points.length;
461//
462// if(n == 0) return(null);
463// }
464// /*-------------------------------------------------------------------*/
465// /* Schneiden an oberer Kante */
466// /* */
467// if(greater(ps.getX2Maximum(), x22))
468// {
469// ps.clear();
470// last = points[0];
471// if(greater(points[0].x2, x22)) flag = false;
472// else
473// {
474// ps.add(points[0]);
475// flag = true;
476// }
477// for(i=1; i<n; i++)
478// {
479// if(greater((*points)[i]->x2, x22))
480// {
481// if(flag)
482// {
483// f = (x22-(*points)[i]->x2)/(points[i].x2-last.x2);
484// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, x22, points[i].x3 +
485//(points[i].x3-last.x3)*f));
486// }
487// flag = false;
488// }
489// else
490// {
491// if(!flag)
492// {
493// f = (x22-points[i].x2)/(points[i].x2-last.x2);
494// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, x22, points[i].x3 +
495//(points[i].x3-last.x3)*f));
496// }
497// ps.add(points[i]);
498// flag = true;
499// }
500// last = points[i];
501// }
502// if(!((greater(points[0].x2, x22)) ^ flag))
503// {
504// f = (x22-points[0].x2)/(points[0].x2-last.x2);
505// ps.add(new GbPoint3D(points[0].x1 + (points[0].x1-last.x1)*f, x22, points[0].x3 + (points[0].x3-last.x3)*f));
506// }
507//
508// points = ps.getPoints();
509// n = points.length;
510//
511// if(n == 0) return(null);
512// }
513// /*-------------------------------------------------------------------*/
514// /* Schneiden an linker Kante */
515// /* */
516// if(less(ps.getX1Minimum(), x11))
517// {
518// ps.clear();
519// last = points[0];
520// if(less(points[0].x1, x11)) flag = false;
521// else
522// {
523// ps.add(points[0]);
524// flag = true;
525// }
526// for(i=1; i<n; i++)
527// {
528// if(less(points[i].x1, x11))
529// {
530// if(flag)
531// {
532// f = (x11-points[i].x1)/(points[i].x1-last.x1);
533// ps.add(new GbPoint3D(x11, points[i].x2 + (points[i].x2-last.x2)*f, points[i].x3 +
534//(points[i].x3-last.x3)*f));
535// }
536// flag = false;
537// }
538// else
539// {
540// if(!flag)
541// {
542// f = (x11-points[i].x1)/(points[i].x1-last.x1);
543// ps.add(new GbPoint3D(x11, points[i].x2 + (points[i].x2-last.x2)*f, points[i].x3 +
544//(points[i].x3-last.x3)*f));
545// }
546// ps.add(points[i]);
547// flag = true;
548// }
549// last = points[i];
550// }
551// if(!((less(points[0].x1, x11)) ^ flag))
552// {
553// f = (x11-points[0].x1)/(points[0].x1-last.x1);
554// ps.add(new GbPoint3D(x11, points[0].x2 + (points[0].x2-last.x2)*f, points[0].x3 + (points[0].x3-last.x3)*f));
555// }
556//
557// points = ps.getPoints();
558// n = points.length;
559//
560// if(n == 0) return(null);
561// }
562// /*-------------------------------------------------------------------*/
563// GbPolygon3D polygon = new GbPolygon3D(points);
564//
565// if(n > 2)
566// {
567// for(i=2; i<n; i++) if(zero(i_TA(points[i-2], points[i-1], points[i]))) polygon.deletePoint(points[i-1]);
568// if(zero(i_TA(points[n-2], points[n-1], points[0]))) polygon.deletePoint(points[n-1]);
569// if(zero(i_TA(points[n-1], points[0], points[1]))) polygon.deletePoint(points[0]);
570// }
571// return(polygon);
572// }
573// final static GbPolygon3D clipPolygon3D(GbPoint3D points[], double x13, double x23)
574// {
575// GbPoint3D last = null;
576// PointSet3 ps = new PointSet3(points);
577// boolean flag = false;
578// int n = points.length;
579// int i;
580// double f;
581//
582// if(n == 0) return(null);
583// if(greater(x13, x23)) { double az = x13; x13 = x23; x23 = az; }
584//
585// /*-------------------------------------------------------------------*/
586// /* Schneiden an vorderer Kante */
587// /* */
588// if(less(ps.getX3Minimum(), x13))
589// {
590// ps.clear();
591// last = points[0];
592// if(less(points[0].x3, x13)) flag = false;
593// else
594// {
595// ps.add(points[0]);
596// flag = true;
597// }
598// for(i=1; i<n; i++)
599// {
600// if(less(points[i].x3, x13))
601// {
602// if(flag)
603// {
604// f = (x13-points[i].x3)/(points[i].x3-last.x3);
605// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, points[i].x2 + (points[i].x2-last.x2)*f,
606//x13));
607// }
608// flag = false;
609// }
610// else
611// {
612// if(!flag)
613// {
614// f = (x13-points[i].x3)/(points[i].x3-last.x3);
615// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, points[i].x2 + (points[i].x2-last.x2)*f,
616//x13));
617// }
618// ps.add(points[i]);
619// flag = true;
620// }
621// last = points[i];
622// }
623// if(!((less(points[0].x3, x13)) ^ flag))
624// {
625// f = (x13-points[0].x3)/(points[0].x3-last.x3);
626// ps.add(new GbPoint3D(points[0].x1 + (points[0].x1-last.x1)*f, points[0].x2 + (points[0].x2-last.x2)*f, x13));
627// }
628//
629// points = ps.getPoints();
630// n = points.length;
631//
632// if(n == 0) return(null);
633// }
634// /*-------------------------------------------------------------------*/
635// /* Schneiden an hinterer Kante */
636// /* */
637// if(greater(ps.getX3Maximum(), x23))
638// {
639// ps.clear();
640// last = points[0];
641// if(greater(points[0].x3, x23)) flag = false;
642// else
643// {
644// ps.add(points[0]);
645// flag = true;
646// }
647// for(i=1; i<n; i++)
648// {
649// if(greater(points[i].x3, x23))
650// {
651// if(flag)
652// {
653// f = (x23-points[i].x3)/(points[i].x3-last.x3);
654// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, points[i].x2 + (points[i].x2-last.x2)*f,
655//x23));
656// }
657// flag = false;
658// }
659// else
660// {
661// if(!flag)
662// {
663// f = (x23-points[i].x3)/(points[i].x3-last.x3);
664// ps.add(new GbPoint3D(points[i].x1 + ((*points)[i]->x1-last.x1)*f, (*points)[i]->x2 +
665//((*points)[i]->x2-last.x2)*f, x23));
666// }
667// ps.add(points[i]);
668// flag = true;
669// }
670// last = points[i];
671// }
672// if(!((greater(points[0].x3, x23)) ^ flag))
673// {
674// f = (x23-points[0].x3)/(points[0].x3-last.x3);
675// ps.add(new GbPoint3D(points[0].x1 + (points[0].x1-last.x1)*f, points[0].x2 + (points[0].x2-last.x2)*f, x23));
676// }
677//
678// points = ps.getPoints();
679// n = points.length;
680//
681// if(n == 0) return(null);
682// }
683// /*-------------------------------------------------------------------*/
684// GbPolygon3D polygon = new GbPolygon3D(points);
685//
686// return(polygon);
687// }
688GbPolygon3D *gb_system_3d::clipPolygon3D(vector<GbPoint3D> points, double x11, double x12, double x13, double x21,
689 double x22, double x23)
690{
691 GbPoint3D last;
692 PointSet3 ps(points);
693 bool flag = false;
694 int n = (int)points.size();
695 int i;
696 double f;
697
698 if (n == 0)
699 return NULL;
700 if (ub_math::greater(x11, x21)) {
701 double ax = x11;
702 x11 = x21;
703 x21 = ax;
704 }
705 if (ub_math::greater(x12, x22)) {
706 double ay = x12;
707 x12 = x22;
708 x22 = ay;
709 }
710 if (ub_math::greater(x13, x23)) {
711 double az = x13;
712 x13 = x23;
713 x23 = az;
714 }
715
716 /*-------------------------------------------------------------------*/
717 /* Schneiden an vorderer Kante */
718 /* */
719 if (ub_math::less(ps.getX3Minimum(), x13)) {
720 ps.clear();
721 last = (points)[0];
722 if (ub_math::less((points)[0].x3, x13))
723 flag = false;
724 else {
725 ps.add((points)[0]);
726 flag = true;
727 }
728 for (i = 1; i < n; i++) {
729 if (ub_math::less((points)[i].x3, x13)) {
730 if (flag) {
731 f = (x13 - (points)[i].x3) / ((points)[i].x3 - last.x3);
732 ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f,
733 (points)[i].x2 + ((points)[i].x2 - last.x2) * f, x13));
734 }
735 flag = false;
736 } else {
737 if (!flag) {
738 f = (x13 - (points)[i].x3) / ((points)[i].x3 - last.x3);
739 ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f,
740 (points)[i].x2 + ((points)[i].x2 - last.x2) * f, x13));
741 }
742 ps.add((points)[i]);
743 flag = true;
744 }
745 last = (points)[i];
746 }
747 if (!((ub_math::less((points)[0].x3, x13)) ^ flag)) {
748 f = (x13 - (points)[0].x3) / ((points)[0].x3 - last.x3);
749 ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1 - last.x1) * f,
750 (points)[0].x2 + ((points)[0].x2 - last.x2) * f, x13));
751 }
752
753 points = ps.getPoints();
754 n = (int)points.size();
755
756 if (n == 0)
757 return NULL;
758 }
759
760 /*-------------------------------------------------------------------*/
761 /* Schneiden an unterer Kante */
762 /* */
763 if (ub_math::less(ps.getX2Minimum(), x12)) {
764 ps.clear();
765 last = (points)[0];
766 if (ub_math::less((points)[0].x2, x12))
767 flag = false;
768 else {
769 ps.add((points)[0]);
770 flag = true;
771 }
772 for (i = 1; i < n; i++) {
773 if (ub_math::less((points)[i].x2, x12)) {
774 if (flag) {
775 f = (x12 - (points)[i].x2) / ((points)[i].x2 - last.x2);
776 ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, x12,
777 (points)[i].x3 + ((points)[i].x3 - last.x3) * f));
778 }
779 flag = false;
780 } else {
781 if (!flag) {
782 f = (x12 - (points)[i].x2) / ((points)[i].x2 - last.x2);
783 ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, x12,
784 (points)[i].x3 + ((points)[i].x3 - last.x3) * f));
785 }
786 ps.add((points)[i]);
787 flag = true;
788 }
789 last = (points)[i];
790 }
791 if (!((ub_math::less((points)[0].x2, x12)) ^ flag)) {
792 f = (x12 - (points)[0].x2) / ((points)[0].x2 - last.x2);
793 ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1 - last.x1) * f, x12,
794 (points)[0].x3 + ((points)[0].x3 - last.x3) * f));
795 }
796
797 points = ps.getPoints();
798 n = (int)points.size();
799
800 if (n == 0)
801 return NULL;
802 }
803 /*-------------------------------------------------------------------*/
804 /* Schneiden an rechter Kante */
805 /* */
806
807 if (ub_math::greater(ps.getX1Maximum(), x21)) {
808 ps.clear();
809 last = (points)[0];
810 if (ub_math::greater((points)[0].x1, x21))
811 flag = false;
812 else {
813 ps.add((points)[0]);
814 flag = true;
815 }
816 for (i = 1; i < n; i++) {
817 if (ub_math::greater((points)[i].x1, x21)) {
818 if (flag) {
819 f = (x21 - (points)[i].x1) / ((points)[i].x1 - last.x1);
820 ps.add(GbPoint3D(x21, (points)[i].x2 + ((points)[i].x2 - last.x2) * f,
821 (points)[i].x3 + ((points)[i].x3 - last.x3) * f));
822 }
823 flag = false;
824 } else {
825 if (!flag) {
826 f = (x21 - (points)[i].x1) / ((points)[i].x1 - last.x1);
827 ps.add(GbPoint3D(x21, (points)[i].x2 + ((points)[i].x2 - last.x2) * f,
828 (points)[i].x3 + ((points)[i].x3 - last.x3) * f));
829 }
830 ps.add((points)[i]);
831 flag = true;
832 }
833 last = (points)[i];
834 }
835 if (!((ub_math::greater((points)[0].x1, x21)) ^ flag)) {
836 f = (x21 - (points)[0].x1) / ((points)[0].x1 - last.x1);
837 ps.add(GbPoint3D(x21, (points)[0].x2 + ((points)[0].x2 - last.x2) * f,
838 (points)[0].x3 + ((points)[0].x3 - last.x3) * f));
839 }
840
841 points = ps.getPoints();
842 n = (int)points.size();
843
844 if (n == 0)
845 return NULL;
846 }
847 /*-------------------------------------------------------------------*/
848 /* Schneiden an hinterer Kante */
849 /* */
850 if (ub_math::greater(ps.getX3Maximum(), x23)) {
851 ps.clear();
852 last = (points)[0];
853 if (ub_math::greater((points)[0].x3, x23))
854 flag = false;
855 else {
856 ps.add((points)[0]);
857 flag = true;
858 }
859 for (i = 1; i < n; i++) {
860 if (ub_math::greater((points)[i].x3, x23)) {
861 if (flag) {
862 f = (x23 - (points)[i].x3) / ((points)[i].x3 - last.x3);
863 ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f,
864 (points)[i].x2 + ((points)[i].x2 - last.x2) * f, x23));
865 }
866 flag = false;
867 } else {
868 if (!flag) {
869 f = (x23 - (points)[i].x3) / ((points)[i].x3 - last.x3);
870 ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f,
871 (points)[i].x2 + ((points)[i].x2 - last.x2) * f, x23));
872 }
873 ps.add((points)[i]);
874 flag = true;
875 }
876 last = (points)[i];
877 }
878 if (!((ub_math::greater((points)[0].x3, x23)) ^ flag)) {
879 f = (x23 - (points)[0].x3) / ((points)[0].x3 - last.x3);
880 ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1 - last.x1) * f,
881 (points)[0].x2 + ((points)[0].x2 - last.x2) * f, x23));
882 }
883
884 points = ps.getPoints();
885 n = (int)points.size();
886
887 if (n == 0)
888 return NULL;
889 }
890 /*-------------------------------------------------------------------*/
891 /* Schneiden an oberer Kante */
892 /* */
893
894 if (ub_math::greater(ps.getX2Maximum(), x22)) {
895 ps.clear();
896 last = (points)[0];
897 if (ub_math::greater((points)[0].x2, x22))
898 flag = false;
899 else {
900 ps.add((points)[0]);
901 flag = true;
902 }
903 for (i = 1; i < n; i++) {
904 if (ub_math::greater((points)[i].x2, x22)) {
905 if (flag) {
906 f = (x22 - (points)[i].x2) / ((points)[i].x2 - last.x2);
907 ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, x22,
908 (points)[i].x3 + ((points)[i].x3 - last.x3) * f));
909 }
910 flag = false;
911 } else {
912 if (!flag) {
913 f = (x22 - (points)[i].x2) / ((points)[i].x2 - last.x2);
914 ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, x22,
915 (points)[i].x3 + ((points)[i].x3 - last.x3) * f));
916 }
917 ps.add((points)[i]);
918 flag = true;
919 }
920 last = (points)[i];
921 }
922 if (!((ub_math::greater((points)[0].x2, x22)) ^ flag)) {
923 f = (x22 - (points)[0].x2) / ((points)[0].x2 - last.x2);
924 ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1 - last.x1) * f, x22,
925 (points)[0].x3 + ((points)[0].x3 - last.x3) * f));
926 }
927
928 points = ps.getPoints();
929 n = (int)points.size();
930
931 if (n == 0)
932 return NULL;
933 }
934 /*-------------------------------------------------------------------*/
935 /* Schneiden an linker Kante */
936 /* */
937 if (ub_math::less(ps.getX1Minimum(), x11)) {
938 ps.clear();
939 last = (points)[0];
940 if (ub_math::less((points)[0].x1, x11))
941 flag = false;
942 else {
943 ps.add((points)[0]);
944 flag = true;
945 }
946 for (i = 1; i < n; i++) {
947 if (ub_math::less((points)[i].x1, x11)) {
948 if (flag) {
949 f = (x11 - (points)[i].x1) / ((points)[i].x1 - last.x1);
950 ps.add(GbPoint3D(x11, (points)[i].x2 + ((points)[i].x2 - last.x2) * f,
951 (points)[i].x3 + ((points)[i].x3 - last.x3) * f));
952 }
953 flag = false;
954 } else {
955 if (!flag) {
956 f = (x11 - (points)[i].x1) / ((points)[i].x1 - last.x1);
957 ps.add(GbPoint3D(x11, (points)[i].x2 + ((points)[i].x2 - last.x2) * f,
958 (points)[i].x3 + ((points)[i].x3 - last.x3) * f));
959 }
960 ps.add((points)[i]);
961 flag = true;
962 }
963 last = (points)[i];
964 }
965 if (!((ub_math::less((points)[0].x1, x11)) ^ flag)) {
966 f = (x11 - (points)[0].x1) / ((points)[0].x1 - last.x1);
967 ps.add(GbPoint3D(x11, (points)[0].x2 + ((points)[0].x2 - last.x2) * f,
968 (points)[0].x3 + ((points)[0].x3 - last.x3) * f));
969 }
970
971 points = ps.getPoints();
972 n = (int)points.size();
973
974 if (n == 0)
975 return NULL;
976 }
977 /*-------------------------------------------------------------------*/
978 return new GbPolygon3D(points);
979}
980/*=========================================================================*/
981GbCuboid3D *gb_system_3d::clipRectangle3D(GbPoint3D &p1, GbPoint3D &p2, double x11, double x12, double x13, double x21,
982 double x22, double x23)
983{
984 double r11 = p1.x1;
985 double r12 = p1.x2;
986 double r13 = p1.x3;
987 double r21 = p2.x1;
988 double r22 = p2.x2;
989 double r23 = p2.x3;
990
991 if (ub_math::greater(x11, x21)) {
992 double ax = x11;
993 x11 = x21;
994 x21 = ax;
995 }
996 if (ub_math::greater(x12, x22)) {
997 double ay = x12;
998 x12 = x22;
999 x22 = ay;
1000 }
1001 if (ub_math::greater(x13, x23)) {
1002 double az = x13;
1003 x13 = x23;
1004 x23 = az;
1005 }
1006 if (ub_math::greater(r11, r21)) {
1007 double bx = r11;
1008 r11 = r21;
1009 r21 = bx;
1010 }
1011 if (ub_math::greater(r12, r22)) {
1012 double by = r12;
1013 r12 = r22;
1014 r22 = by;
1015 }
1016 if (ub_math::greater(r13, r23)) {
1017 double bz = r13;
1018 r13 = r23;
1019 r23 = bz;
1020 }
1021
1022 double m11 = ub_math::greater(x11, r11) ? x11 : r11;
1023 double m12 = ub_math::greater(x12, r12) ? x12 : r12;
1024 double m13 = ub_math::greater(x13, r13) ? x13 : r13;
1025 double m21 = ub_math::greater(x21, r21) ? r21 : x21;
1026 double m22 = ub_math::greater(x22, r22) ? r22 : x22;
1027 double m23 = ub_math::greater(x23, r23) ? r23 : x23;
1028
1030 return (new GbCuboid3D(new GbPoint3D(m11, m12, m13), new GbPoint3D(m21, m22, m23)));
1031 else
1032 return (NULL);
1033}
1034
1035/*=========================================================================*/
1036/*=========================================================================*/
1037/*=========================================================================*/
1038
1040{
1041 this->init();
1042 this->points.reserve(n); // reserves n elements! but the size of the vector ist still "0"
1043}
1044/*=======================================================*/
1046{
1047 this->init();
1048 this->add(points);
1049}
1050/*=======================================================*/
1052{
1053 // is point equal to last point in points then return
1054 if (!this->points.empty() && point.equals(&this->points.back()))
1055 return; // WHY???
1056
1057 // push point to vector
1058 this->points.push_back(point);
1059
1060 this->consistent = false;
1061}
1062/*=======================================================*/
1064{
1065 if (this->containsEqual(point) > 0)
1066 return;
1067
1068 this->points.push_back(point);
1069 this->consistent = false;
1070}
1071/*=======================================================*/
1073{
1074 for (int pos = 0; pos < (int)pointVector.size(); pos++)
1075 this->points.push_back(pointVector[pos]);
1076
1077 this->consistent = false;
1078}
1079/*=======================================================*/
1081{
1082 if (index < 0 || index >= (int)this->points.size())
1083 throw UbException(UB_EXARGS, "index out of range");
1084
1085 // get iterator for index-position
1086 vector<GbPoint3D>::iterator pos = this->points.begin();
1087 for (int i = 1; i <= index; i++)
1088 ++pos;
1089
1090 // insert point
1091 this->points.insert(pos, point);
1092
1093 this->consistent = false;
1094}
1095/*=======================================================*/
1096// void delete(GbPoint3D point)
1097//{
1098// for(int i=this.size-1; i>=0; i--) if(this.points[i] == point) this.delete(i);
1099//}
1100/*=======================================================*/
1101// void delete(int index)
1102//{
1103// int j = this.size - index - 1;
1104// if(j > 0) System.arraycopy(this.points, index + 1, this.points, index, j);
1105// this.consistent = false;
1106// this.size--;
1107//}
1108/*=======================================================*/
1110{
1111 // clears points (size==0 but capacity is the old c1)
1112 this->points.clear();
1113 this->consistent = false;
1114}
1115/*=======================================================*/
1117{
1118 // clears points (size==0 AND capacity==0)
1119 this->points.resize(0);
1120 this->consistent = false;
1121}
1122/*=======================================================*/
1124{
1125 if (!this->consistent)
1126 this->calculateValues();
1127 return this->x1min;
1128}
1129/*=======================================================*/
1131{
1132 if (!this->consistent)
1133 this->calculateValues();
1134 return this->x1max;
1135}
1136/*=======================================================*/
1138{
1139 if (!this->consistent)
1140 this->calculateValues();
1141 return this->x2min;
1142}
1143/*=======================================================*/
1145{
1146 if (!this->consistent)
1147 this->calculateValues();
1148 return this->x2max;
1149}
1150/*=======================================================*/
1152{
1153 if (!this->consistent)
1154 this->calculateValues();
1155 return this->x3min;
1156}
1157/*=======================================================*/
1159{
1160 if (!this->consistent)
1161 this->calculateValues();
1162 return this->x3max;
1163}
1164/*=======================================================*/
1166{
1167 // returns number of points which has the same adress (this should be 0 or 1!!!)
1168 int n = 0;
1169
1170 for (int pos = (int)this->points.size() - 1; pos >= 0; pos--)
1171 if (&this->points[pos] == point)
1172 n++;
1173
1174 return n;
1175}
1176/*=======================================================*/
1178{
1179 // returns number of points which have the same coordinates with point (could be 0,1 or even more)
1180 int n = 0;
1181
1182 for (int pos = (int)this->points.size() - 1; pos >= 0; pos--)
1183 if (this->points[pos].equals(&point))
1184 n++;
1185
1186 return n;
1187}
1188/*=======================================================*/
1190{
1191 // returns true if pointset has c2 in "this->points"vector neighboured points
1192 // wich have the same adress as point1 or point2
1193 vector<GbPoint3D>::iterator pos1 = this->points.begin();
1195
1196 for (pos2 = pos1++; pos2 != this->points.end(); ++pos2) {
1197 if (&(*pos1) == point1 && &(*pos2) == point2)
1198 return true;
1199 else if (&(*pos1) == point2 && &(*pos2) == point1)
1200 return true;
1201
1202 pos1 = pos2;
1203 }
1204
1205 return false;
1206}
1207/*=======================================================*/
1209{
1210 // returns true if pointset has c2 in "this->points"vector neighboured points
1211 // wich have the same coordinates as point1 or point2
1212 vector<GbPoint3D>::iterator pos1 = this->points.begin();
1214
1215 for (pos2 = pos1++; pos2 != this->points.end(); ++pos2) {
1216 if ((*pos1).equals(&point1) && (*pos2).equals(&point2))
1217 return true;
1218 else if ((*pos1).equals(&point2) && (*pos2).equals(&point1))
1219 return true;
1220
1221 pos1 = pos2;
1222 }
1223
1224 return false;
1225}
1226/*=======================================================*/
1228{
1229 if (index < 0 || index >= (int)this->points.size())
1230 throw UbException(UB_EXARGS, "index out of range");
1231 return &(this->points)[index];
1232}
1233/*=======================================================*/
1234GbPoint3D *gb_system_3d::PointSet3::getFirstPoint() { return &(this->points.front()); }
1235/*=======================================================*/
1236GbPoint3D *gb_system_3d::PointSet3::getLastPoint() { return &(this->points.back()); }
1237/*=======================================================*/
1238int gb_system_3d::PointSet3::size() { return (int)this->points.size(); }
1239/*=======================================================*/
1241{
1242 // is this right? it's another effect as at GbPoint3D* getNode(index)!!!
1243 // or do we want to have the next uncommented getPoints() funktion
1244 return this->points;
1245}
1247// vector<GbPoint3D*> gb_system_3d::PointSet3::getPoints()
1248//{
1249// vector<GbPoint3D*> tmp;
1250// for(int pos=0; pos<(int)this->points.size();pos++) tmp.push_back(&this->points[pos]);
1251//
1252// return tmp;
1253//}
1254/*=======================================================*/
1256{
1257 if (this->points.empty()) {
1258 this->x1min = this->x2min = this->x3min = 0.0;
1259 this->x1max = this->x2max = this->x3max = 0.0;
1260 } else {
1261 this->x1min = (this->points)[0].x1;
1262 this->x1max = (this->points)[0].x1;
1263 this->x2min = (this->points)[0].x2;
1264 this->x2max = (this->points)[0].x2;
1265 this->x3min = (this->points)[0].x3;
1266 this->x3max = (this->points)[0].x3;
1267
1268 for (int i = (int)this->points.size() - 1; i > 0; --i) {
1269 if ((this->points)[i].x1 < this->x1min)
1270 this->x1min = (this->points)[i].x1;
1271 if ((this->points)[i].x1 > this->x1max)
1272 this->x1max = (this->points)[i].x1;
1273 if ((this->points)[i].x2 < this->x2min)
1274 this->x2min = (this->points)[i].x2;
1275 if ((this->points)[i].x2 > this->x2max)
1276 this->x2max = (this->points)[i].x2;
1277 if ((this->points)[i].x3 < this->x3min)
1278 this->x3min = (this->points)[i].x3;
1279 if ((this->points)[i].x3 > this->x3max)
1280 this->x3max = (this->points)[i].x3;
1281 }
1282 }
1283 this->consistent = true;
1284}
1285
This Class provides basic 3D box objects.
Definition GbCuboid3D.h:53
This Class provides basic 3D line objects.
Definition GbLine3D.h:59
This Class provides basic 3D point objects.
Definition GbPoint3D.h:49
double x1
Definition GbPoint3D.h:121
double x3
Definition GbPoint3D.h:123
double x2
Definition GbPoint3D.h:122
This Class provides basic 3D polygon objects.
Definition GbPolygon3D.h:53
std::shared_ptr< T > SPtr
int contains(GbPoint3D *point)
void add(const GbPoint3D &point)
GbPoint3D * getPoint(int index)
int containsEqual(const GbPoint3D &point)
bool containsEqualLine(const GbPoint3D &point1, const GbPoint3D &point2)
void calculateValues()
*=======================================================*‍/
void addUnequal(const GbPoint3D &point)
std::vector< GbPoint3D > getPoints()
bool containsLine(GbPoint3D *point1, GbPoint3D *point2)
void insert(const GbPoint3D &point, int index)
GbPoint3D * getFirstPoint()
#define UB_EXARGS
Definition UbException.h:73
bool hasIntersectionPoint3D(GbPoint3D &p11, GbPoint3D &p12, GbPoint3D &p21, GbPoint3D &p22)
GbPoint3D * calculateIntersectionPoint3D(GbPoint3D &p11, GbPoint3D &p12, GbPoint3D &p21, GbPoint3D &p22)
bool isParallelIn3D(GbPoint3D &p11, GbPoint3D &p12, GbPoint3D &p21, GbPoint3D &p22)
GbPolygon3D * clipPolygon3D(std::vector< GbPoint3D > points, double x11, double x12, double x13, double x21, double x22, double x23)
double getDistance(const GbPoint3D &p11, const GbPoint3D &p12)
GbCuboid3D * clipRectangle3D(GbPoint3D &p1, GbPoint3D &p2, double x11, double x12, double x13, double x21, double x22, double x23)
GbLine3D * createClipLine3D(GbPoint3D &p1, GbPoint3D &p2, double x11, double x12, double x13, double x21, double x22, double x23)
bool lessEqual(const T1 &value, const T2 &reference)
Definition UbMath.h:209
bool greater2(const T1 &value1, const T2 &value2, T3 toBeGreaterAs1, T4 toBeGreaterAs2)
Definition UbMath.h:302
bool less2(const T1 &value1, const T2 &value2, T3 toBeLessAs1, T4 toBeLessAs2)
Definition UbMath.h:295
bool greater(const T1 &value, const T2 &reference)
Definition UbMath.h:216
bool inClosedInterval(const T1 &value, const T2 &threshold1, const T3 &threshold2)
Definition UbMath.h:309
bool zero(const T &value)
Definition UbMath.h:139
bool less(const T1 &value, const T2 &reference)
Definition UbMath.h:202