VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
Vertex.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 "Vertex.h"
35
36#include "utilities/math/Math.h"
37
38namespace vf::gpu {
39
41Vertex::Vertex() { x = 0.0f; y = 0.0f; z = 0.0f; }
42
44{
45 return vf::Math::sqrtReal((x - w.x)*(x - w.x) + (y - w.y)*(y - w.y) + (z - w.z)*(z - w.z));
46}
47
49{
50 return Vertex(x - v.x, y - v.y, z - v.z);
51}
52
54{
55 return Vertex(this->x + v.x, this->y + v.y, this->z + v.z);
56}
57
58Vertex Vertex::operator*(const real& value) const
59{
60 return Vertex(value * this->x, value * this->y, value * this->z);
61}
62
63Vertex Vertex::operator/(const real& value) const
64{
65 return *this * ((real)1.0 / value);
66}
67
69{
70 return x*w.x + y*w.y + z*w.z;
71}
72
73struct Vertex Vertex::crossProduct(const Vertex &w) const
74{
75 real a = y*w.z - z*w.y;
76 real b = z*w.x - x*w.z;
77 real c = x*w.y - y*w.x;
78 return Vertex(a, b, c);
79}
80
82{
83 return vf::Math::sqrtReal(x * x + y * y + z * z);
84}
85
87{
88 real len = length();
89
90 if (len > EPSILON)
91 {
92 real invLen = 1.0f / len;
93 x *= invLen;
94 y *= invLen;
95 z *= invLen;
96 }
97}
98
100{
101 real temp = x*x + y*y + z*z;
102 return vf::Math::sqrtReal(temp);
103}
104
105int Vertex::isEqual(const Vertex &w) const
106{
107 return vf::Math::equal(x, w.x) && vf::Math::equal(y, w.y) && vf::Math::equal(z, w.z);
108}
109
111{
112 if (isEqual(w))
113 return 0.0;
114 if (this->getMagnitude() == 0 || w.getMagnitude() == 0)
115 return 0.0;
116
117 real mag = this->getMagnitude() * w.getMagnitude();
118 real skal = *this * w;
119 if (mag - std::abs(skal) < 0.0001)
120 return 0.0f;
121 return vf::Math::acosReal(skal / mag) * 180.0f / vf::Math::acosReal(-1.0f); // acos(-1.0f) = PI
122}
123
124void Vertex::print() const
125{
126 printf("(%2.8f,%2.8f,%2.8f)\n", x, y, z);
127}
128
129void Vertex::print(std::ostream &ost) const
130{
131 ost.write((char*)&x, 4);
132 ost.write((char*)&y, 4);
133 ost.write((char*)&z, 4);
134}
135
136void Vertex::printFormatted(std::ostream &ost) const
137{
138 ost << x << " " << y << " " << z;
139}
140
141
142
143bool Vertex::operator==(const Vertex &v) const
144{
145 return vf::Math::equal(x, v.x) && vf::Math::equal(y, v.y) && vf::Math::equal(z, v.z);
146}
147
148
149bool Vertex::isXbetween(real min, real max) const
150{
151 return x >= min && x <= max;
152}
153
154bool Vertex::isYbetween(real min, real max) const
155{
156 return y >= min && y <= max;
157}
158
159bool Vertex::isZbetween(real min, real max) const
160{
161 return z >= min && z <= max;
162}
163
164void Vertex::setMinMax(real & minX, real & maxX, real & minY, real & maxY, real & minZ, real & maxZ, const Vertex & v1, const Vertex & v2, const Vertex & v3)
165{
166 calculateMinMax(v1.x, v2.x, v3.x, minX, maxX);
167 calculateMinMax(v1.y, v2.y, v3.y, minY, maxY);
168 calculateMinMax(v1.z, v2.z, v3.z, minZ, maxZ);
169}
170
171
172real getMinimum(const real &value1, const real &value2)
173{
174 return value1 < value2 ? value1 : value2;
175}
176
177real getMaximum(const real &value1, const real &value2)
178{
179 return value1 > value2 ? value1 : value2;
180}
181
182
183void Vertex::calculateMinMax(const real &value1, const real &value2, const real &value3, real &min, real &max)
184{
185
186 real newMinimum = value1;
189
190 real newMaximum = value1;
193
194 min = newMinimum;
195 max = newMaximum;
196}
197
198}
199
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
@ z
Definition Axis.h:44
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43
#define EPSILON
Definition Math.h:40
static real acosReal(const real &val)
Definition Math.cpp:75
static real sqrtReal(const real &val)
Definition Math.cpp:66
static bool equal(const real &val1, const real &val2, real maxRelDiff=EPSILON)
Definition Math.cpp:40
real getMaximum(const real &value1, const real &value2)
Definition Vertex.cpp:177
real getMinimum(const real &value1, const real &value2)
Definition Vertex.cpp:172
real getEuclideanDistanceTo(const Vertex &w) const
Definition Vertex.cpp:43
Vertex operator/(const real &value) const
Definition Vertex.cpp:63
real getMagnitude() const
Definition Vertex.cpp:99
static void setMinMax(real &minX, real &maxX, real &minY, real &maxY, real &minZ, real &maxZ, const Vertex &v1, const Vertex &v2, const Vertex &v3)
Definition Vertex.cpp:164
void printFormatted(std::ostream &ost) const
Definition Vertex.cpp:136
bool isXbetween(real min, real max) const
Definition Vertex.cpp:149
Vertex operator+(const Vertex &v) const
Definition Vertex.cpp:53
Vertex operator-(const Vertex &v) const
Definition Vertex.cpp:48
bool operator==(const Vertex &v) const
Definition Vertex.cpp:143
static void calculateMinMax(const real &value1, const real &value2, const real &value3, real &min, real &max)
Definition Vertex.cpp:183
real length() const
Definition Vertex.cpp:81
int isEqual(const Vertex &w) const
Definition Vertex.cpp:105
bool isZbetween(real min, real max) const
Definition Vertex.cpp:159
Vertex operator*(const real &value) const
Definition Vertex.cpp:58
real getInnerAngle(const Vertex &w) const
Definition Vertex.cpp:110
void normalize()
Definition Vertex.cpp:86
bool isYbetween(real min, real max) const
Definition Vertex.cpp:154
void print() const
Definition Vertex.cpp:124