VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GbVector3D.h
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#ifndef GBVECTOR3D_H
35#define GBVECTOR3D_H
36
37#include <cassert>
38#include <cfloat>
39#include <string>
40
41#include <PointerDefinitions.h>
42
43class GbPoint3D;
44
47{
48public:
49 // construction
50 GbVector3D();
51 GbVector3D(const double &fX1, const double &fX2, const double &fX3);
53 GbVector3D(const GbPoint3D &rkV);
54
55 std::string toString();
56
57 // coordinate access
58 operator const double *() const;
59 operator double *();
60 double operator[](int i) const;
61 double &operator[](int i);
62 double X1() const;
63 double &X1();
64 double X2() const;
65 double &X2();
66 double X3() const;
67 double &X3();
68
69 // assignment
71
72 // comparison
73 bool operator==(const GbVector3D &rkV) const;
74 bool operator!=(const GbVector3D &rkV) const;
75 bool operator<(const GbVector3D &rkV) const;
76 bool operator<=(const GbVector3D &rkV) const;
77 bool operator>(const GbVector3D &rkV) const;
78 bool operator>=(const GbVector3D &rkV) const;
79
80 // arithmetic operations
81 GbVector3D operator+(const GbVector3D &rkV) const;
82 GbVector3D operator-(const GbVector3D &rkV) const;
83 GbVector3D operator*(const double &fScalar) const;
84 GbVector3D operator/(const double &fScalar) const;
85 GbVector3D operator-() const;
86
87 // arithmetic updates
90 GbVector3D &operator*=(const double &fScalar);
91 GbVector3D &operator/=(const double &fScalar);
92
95 GbVector3D Scale(const double &x);
96
97 // vector operations
98 double Length() const;
99 double SquaredLength() const;
100 double Dot(const GbVector3D &rkV) const;
101 double Normalize();
102
103 // The cross products are computed using the right-handed rule. Be aware
104 // that some graphics APIs use a left-handed rule. If you have to compute
105 // a cross product with these functions and send the result to the API
106 // that expects left-handed, you will need to change sign on the vector
107 // (replace each component value c by -c).
108 GbVector3D Cross(const GbVector3D &rkV) const;
109 GbVector3D UnitCross(const GbVector3D &rkV) const;
110
111 // Compute the barycentric coordinates of the point with respect to the
112 // tetrahedron <V0,V1,V2,V3>, P = b0*V0 + b1*V1 + b2*V2 + b3*V3, where
113 // b0 + b1 + b2 + b3 = 1.
114 void GetBarycentrics(const GbVector3D &rkV0, const GbVector3D &rkV1, const GbVector3D &rkV2, const GbVector3D &rkV3,
115 double afBary[4]) const;
116
117 // Gram-Schmidt orthonormalization. Take linearly independent vectors
118 // U, V, and W and compute an orthonormal set (unit length, mutually
119 // perpendicular).
121 static void Orthonormalize(GbVector3D *akV);
122
123 // Input W must be initialized to a nonzero vector, output is {U,V,W},
124 // an orthonormal basis. A hint is provided about whether or not W
125 // is already unit length.
127
128 // special vectors
129 static const GbVector3D ZERO;
130 static const GbVector3D UNIT_X1;
131 static const GbVector3D UNIT_X2;
132 static const GbVector3D UNIT_X3;
133
134private:
135 // support for comparisons
136 int CompareArrays(const GbVector3D &rkV) const;
137
138 double m_afTuple[3];
139};
140
141GbVector3D operator*(const double &fScalar, const GbVector3D &rkV);
142
143#endif // GBVECTOR3D_H
144
This Class provides basic 3D point objects.
Definition GbPoint3D.h:49
This Class provides basic 3D vector objects.
Definition GbVector3D.h:47
std::shared_ptr< T > SPtr
constexpr real3 operator*(const real3 &a, real b)
Definition DataTypes.h:70
GbVector3D & operator+=(const GbVector3D &rkV)
GbVector3D Cross(const GbVector3D &rkV) const
GbVector3D & operator-=(const GbVector3D &rkV)
GbVector3D Subtract(GbVector3D &vector)
double SquaredLength() const
bool operator>=(const GbVector3D &rkV) const
bool operator<=(const GbVector3D &rkV) const
double Length() const
GbVector3D operator-() const
double operator[](int i) const
static const GbVector3D UNIT_X1
Definition GbVector3D.h:130
static const GbVector3D ZERO
Definition GbVector3D.h:129
bool operator==(const GbVector3D &rkV) const
bool operator!=(const GbVector3D &rkV) const
std::string toString()
GbVector3D operator+(const GbVector3D &rkV) const
bool operator<(const GbVector3D &rkV) const
void GetBarycentrics(const GbVector3D &rkV0, const GbVector3D &rkV1, const GbVector3D &rkV2, const GbVector3D &rkV3, double afBary[4]) const
GbVector3D operator/(const double &fScalar) const
static void Orthonormalize(GbVector3D &rkU, GbVector3D &rkV, GbVector3D &rkW)
static void GenerateOrthonormalBasis(GbVector3D &rkU, GbVector3D &rkV, GbVector3D &rkW, bool bUnitLengthW)
static const GbVector3D UNIT_X3
Definition GbVector3D.h:132
double X1() const
double X3() const
double X2() const
static const GbVector3D UNIT_X2
Definition GbVector3D.h:131
GbVector3D & operator*=(const double &fScalar)
bool operator>(const GbVector3D &rkV) const
GbVector3D operator*(const double &fScalar) const
GbVector3D & operator/=(const double &fScalar)
GbVector3D UnitCross(const GbVector3D &rkV) const
double Normalize()
GbVector3D Scale(const double &x)
GbVector3D Add(GbVector3D &vector)
double Dot(const GbVector3D &rkV) const
GbVector3D & operator=(const GbVector3D &rkV)
@ x
Definition Axis.h:42