VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GbLine3D.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 <GbLine3D.h>
36#include <GbSystem3D.h>
37#include <GbTriangle3D.h>
38
39using namespace std;
40
41/*=======================================================*/
43{
44 p1 = NULL;
45 p2 = NULL;
46 length = 0.0;
47}
48/*=======================================================*/
50{
51 this->p1 = point1;
52 this->p2 = point2;
53 this->p1->addObserver(this);
54 this->p2->addObserver(this);
55 this->calculateValues();
56}
57/*=======================================================*/
59{
60 this->p1 = line->p1->clone();
61 this->p2 = line->p2->clone();
62 this->p1->addObserver(this);
63 this->p2->addObserver(this);
64 this->calculateValues();
65}
66/*=======================================================*/
68{
69 if (this->p1)
70 this->p1->removeObserver(this);
71 if (this->p2)
72 this->p2->removeObserver(this);
73}
74/*=======================================================*/
76{
77 if (this->p1) {
78 this->p1->removeObserver(this);
79 this->p1->finalize();
80 delete this->p1;
81 this->p1 = NULL;
82 }
83 if (this->p2) {
84 this->p2->removeObserver(this);
85 this->p2->finalize();
86 delete this->p2;
87 this->p2 = NULL;
88 }
89}
90/*=======================================================*/
102/*=======================================================*/
104{
105 if (this->p1)
106 this->p1->removeObserver(this);
107 this->p1 = point1;
108 this->p1->addObserver(this);
109
110 if (this->p1 && this->p2)
111 this->calculateValues();
112}
113/*=======================================================*/
115{
116 if (this->p2)
117 this->p2->removeObserver(this);
118 this->p2 = point2;
119 this->p2->addObserver(this);
120
121 if (this->p1 && this->p2)
122 this->calculateValues();
123}
124/*=======================================================*/
126{
127 if (this->p1)
128 this->p1->removeObserver(this);
129 if (this->p2)
130 this->p2->removeObserver(this);
131
132 this->p1 = point1;
133 this->p2 = point2;
134
135 this->p1->addObserver(this);
136 this->p2->addObserver(this);
137
138 this->calculateValues();
139}
140/*=======================================================*/
142{
144 ss << "GbLine3D[p1=";
145 ss << this->p1->toString() << ",p2=" << this->p2->toString() << ",l=" << this->getLength() << "]";
146 return (ss.str());
147}
148/*=======================================================*/
150{
151 throw UbException(UB_EXARGS, " not implemented");
152 // return(GbSystem::calculateIntersectionPoint3D(*this->p1, *this->p2, *line->p1, *line->p2));
153}
154/*======================================================================*/
156{
157 return gb_system_3d::createClipLine3D(*this->p1, *this->p2, cuboid->getPoint1()->x1, cuboid->getPoint1()->x2,
158 cuboid->getPoint1()->x3, cuboid->getPoint2()->x1, cuboid->getPoint2()->x2,
159 cuboid->getPoint2()->x3);
160}
161/*======================================================================*/
163{
164 return gb_system_3d::createClipLine3D(*this->p1, *this->p2, pA->x1, pA->x2, pA->x3, pE->x1, pE->x2, pE->x3);
165}
166/*======================================================================*/
167double GbLine3D::getDistance(const GbPoint3D &point) { return this->getDistance(point.x1, point.x2, point.x3); }
168/*======================================================================*/
169double GbLine3D::getDistance(const double &x1, const double &x2, const double &x3)
170{
171 double dx1 = this->p2->x1 - this->p1->x1;
172 double dx2 = this->p2->x2 - this->p1->x2;
173 double dx3 = this->p2->x3 - this->p1->x3;
174
175 // double vec[3];
176 double a0 = x1 - p1->x1;
177 double a1 = x2 - p1->x2;
178 double a2 = x3 - p1->x3;
179
180 double kreuzProd0 = a1 * dx3 - a2 * dx2;
181 double kreuzProd1 = a2 * dx1 - a0 * dx3;
182 double kreuzProd2 = a0 * dx2 - a1 * dx1;
183
184 return (std::sqrt(kreuzProd0 * kreuzProd0 + kreuzProd1 * kreuzProd1 + kreuzProd2 * kreuzProd2)) / length;
185}
186/*=======================================================*/
187void GbLine3D::calculateValues()
188{
189 double dx1 = this->p2->x1 - this->p1->x1;
190 double dx2 = this->p2->x2 - this->p1->x2;
191 double dx3 = this->p2->x3 - this->p1->x3;
192 this->length = std::sqrt(dx1 * dx1 + dx2 * dx2 + dx3 * dx3);
193}
194/*==========================================================*/
196{
197 GbPoint3D *point = dynamic_cast<GbPoint3D *>(changedObject);
198 if (!point || (this->p1 != point && this->p2 != point))
199 return;
200
201 this->calculateValues();
202}
203/*==========================================================*/
205{
206 if (this->p1) {
207 UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p1);
208 if (objectForDeletion == observedObj) {
209 this->p1 = NULL;
210 length = 0.0;
211 }
212 }
213 if (this->p2) {
214 UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p2);
215 if (objectForDeletion == observedObj) {
216 this->p2 = NULL;
217 length = 0.0;
218 }
219 }
220 // ACHTUNG: eigentlich muessten in allen methoden von GbLine if abfragen fuer NULL pointer hin... toDo
221}
222/*==========================================================*/
223void GbLine3D::scale(const double &sx1, const double &sx2, const double &sx3)
224{
225 double p1X1 = this->p1->getX1Coordinate();
226 double p1X2 = this->p1->getX2Coordinate();
227 double p1X3 = this->p1->getX3Coordinate();
228
229 double p2X1 = this->p2->getX1Coordinate();
230 double p2X2 = this->p2->getX2Coordinate();
231 double p2X3 = this->p2->getX3Coordinate();
232
233 double lenX1 = fabs(p1X1 - p2X1);
234 double lenX2 = fabs(p1X2 - p2X2);
235 double lenX3 = fabs(p1X3 - p2X3);
236
237 double deltaX1 = lenX1 * sx1 - lenX1;
238 double deltaX2 = lenX2 * sx2 - lenX2;
239 double deltaX3 = lenX3 * sx3 - lenX3;
240
241 if (p1X1 < p2X1) {
242 p1X1 -= 0.5 * deltaX1;
243 p2X1 += 0.5 * deltaX1;
244 } else {
245 p1X1 += 0.5 * deltaX1;
246 p2X1 -= 0.5 * deltaX1;
247 }
248 if (p1X2 < p2X2) {
249 p1X2 -= 0.5 * deltaX2;
250 p2X2 += 0.5 * deltaX2;
251 } else {
252 p1X2 += 0.5 * deltaX2;
253 p2X2 -= 0.5 * deltaX2;
254 }
255 if (p1X3 < p2X3) {
256 p1X3 -= 0.5 * deltaX3;
257 p2X3 += 0.5 * deltaX3;
258 } else {
259 p1X3 += 0.5 * deltaX3;
260 p2X3 -= 0.5 * deltaX3;
261 }
262
263 this->p1->setCoordinates(p1X1, p1X2, p1X3);
264 this->p2->setCoordinates(p2X1, p2X2, p2X3);
265}
266/*=======================================================*/
267void GbLine3D::translate(const double &tx1, const double &tx2, const double &tx3)
268{
269 this->p1->translate(tx1, tx2, tx3);
270 this->p2->translate(tx1, tx2, tx3);
271 // this->notifyObserversObjectChanged();
272}
273
This Class provides basic 3D box objects.
Definition GbCuboid3D.h:53
GbPoint3D * getPoint1()
Definition GbCuboid3D.h:65
This Class provides basic 3D line objects.
Definition GbLine3D.h:59
double length
Definition GbLine3D.h:154
double getX3Centroid() override
Definition GbLine3D.h:102
double getX1Maximum() override
Definition GbLine3D.h:108
double getX3Maximum() override
Definition GbLine3D.h:110
double getX2Maximum() override
Definition GbLine3D.h:109
double getLength()
Definition GbLine3D.h:98
GbPoint3D * p1
Definition GbLine3D.h:152
double getX1Minimum() override
Definition GbLine3D.h:104
double getX3Minimum() override
Definition GbLine3D.h:106
double getX1Centroid() override
Definition GbLine3D.h:100
GbPoint3D * p2
Definition GbLine3D.h:153
double getX2Minimum() override
Definition GbLine3D.h:105
double getX2Centroid() override
Definition GbLine3D.h:101
This Class provides basic 3D point objects.
Definition GbPoint3D.h:49
double x1
Definition GbPoint3D.h:121
double getX3Coordinate() const
Definition GbPoint3D.h:84
double x3
Definition GbPoint3D.h:123
GbPoint3D * clone() override
Definition GbPoint3D.h:56
void setCoordinates(const double &x1, const double &x2, const double &x3)
Definition GbPoint3D.h:59
double getX1Coordinate() const
Definition GbPoint3D.h:82
void finalize() override
Definition GbPoint3D.h:57
double getX2Coordinate() const
Definition GbPoint3D.h:83
double x2
Definition GbPoint3D.h:122
This Class provides basic 3D triangle objects.
Observable object.
virtual void removeObserver(UbObserver *observer)
virtual void addObserver(UbObserver *observer)
std::shared_ptr< T > SPtr
GbPoint3D * calculateIntersectionPoint3D(GbLine3D *line)
Definition GbLine3D.cpp:149
double getDistance(const GbPoint3D &point)
Definition GbLine3D.cpp:167
void objectChanged(UbObservable *changedObject) override
Definition GbLine3D.cpp:195
void setPoint1(GbPoint3D *point1)
Definition GbLine3D.cpp:103
void translate(const double &x1, const double &x2, const double &x3) override
~GbLine3D() override
Definition GbLine3D.cpp:67
void translate(const double &tx1, const double &tx2, const double &tx3) override
Definition GbLine3D.cpp:267
void finalize() override
Definition GbLine3D.cpp:75
void setPoints(GbPoint3D *point1, GbPoint3D *point2)
Definition GbLine3D.cpp:125
GbLine3D * createClippedLine3D(GbCuboid3D *cuboid)
Definition GbLine3D.cpp:155
std::string toString() override
Definition GbLine3D.cpp:141
void objectWillBeDeleted(UbObservable *objectForDeletion) override
Definition GbLine3D.cpp:204
void setPoint2(GbPoint3D *point2)
Definition GbLine3D.cpp:114
std::vector< GbTriangle3D * > getSurfaceTriangleSet() override
Definition GbLine3D.cpp:91
void scale(const double &sx1, const double &sx2, const double &sx3) override
Definition GbLine3D.cpp:223
std::string toString() override
#define UB_EXARGS
Definition UbException.h:73
GbLine3D * createClipLine3D(GbPoint3D &p1, GbPoint3D &p2, double x11, double x12, double x13, double x21, double x22, double x23)