triad.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::triad
26 
27 Description
28  Representation of a 3D Cartesian coordinate system as a Vector of vectors.
29 
30 See also
31  Foam::quaternion
32 
33 SourceFiles
34  triadI.H
35  triad.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef triad_H
40 #define triad_H
41 
42 #include "vector.H"
43 #include "tensor.H"
44 #include "contiguous.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declaration of classes
52 class Istream;
53 class Ostream;
54 
55 // Forward declaration of friend functions and operators
56 class triad;
57 Istream& operator>>(Istream&, triad&);
58 Ostream& operator<<(Ostream&, const triad&);
59 
60 class quaternion;
61 
62 /*---------------------------------------------------------------------------*\
63  Class triad Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class triad
67 :
68  public Vector<vector>
69 {
70 
71 public:
72 
73  // Constructors
74 
75  //- Construct null
76  inline triad();
77 
78  //- Construct from components
79  inline triad(const Vector<vector>& vv);
80 
81  //- Construct from coordinate axes
82  inline triad(const vector& x, const vector& y, const vector& z);
83 
84  //- Construct from a primary axis with the other two unset
85  inline triad(const vector& pa);
86 
87  //- Construct from a quaternion
88  triad(const quaternion& q);
89 
90  //- Construct from a tensor
91  triad(const tensor& t);
92 
93  //- Construct from Istream
94  inline triad(Istream&);
95 
96 
97  // Static Data Members
98 
99  static const triad I;
100  static const triad unset;
101 
102 
103  // Member Functions
104 
105  //- Is the vector in the direction d set
106  inline bool set(const direction d) const;
107 
108  //- Are all the vector set
109  inline bool set() const;
110 
111  //- Return the primary direction of the vector v
112  static inline direction primaryDirection(const vector& v);
113 
114  //- Return the vector orthogonal to the two provided
115  static inline vector orthogonal(const vector& v1, const vector& v2);
116 
117  //- Orthogonalise this triad so that it is ortho-normal
118  void orthogonalise();
119 
120  //- Normalise each set axis vector to have a unit magnitude
121  void normalise();
122 
123  //- Align this triad with the given vector v
124  // by rotating the most aligned axis to be coincident with v
125  void align(const vector& v);
126 
127  //- Sort the axes such that they are closest to the x, y and z axes
128  triad sortxyz() const;
129 
130  //- Convert to a quaternion
131  operator quaternion() const;
132 
133 
134  // Member Operators
135 
136  inline void operator=(const Vector<vector>&);
137 
138  void operator=(const tensor& t);
139 
140  //- Add the triad t2 to this triad
141  // without normalising or orthogonalising
142  void operator+=(const triad& t2);
143 
144 
145  // IOstream Operators
146 
147  inline friend Istream& operator>>(Istream&, triad&);
148  inline friend Ostream& operator<<(Ostream&, const triad&);
149 };
150 
151 
152 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
153 
154 //- Return a quantity of the difference between two triads
155 scalar diff(const triad& A, const triad& B);
156 
157 //- Data associated with quaternion type are contiguous
158 template<>
159 inline bool contiguous<triad>() {return true;}
160 
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 } // End namespace Foam
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #include "triadI.H"
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 #endif
173 
174 // ************************************************************************* //
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:403
friend Istream & operator>>(Istream &, triad &)
void align(const vector &v)
Align this triad with the given vector v.
Definition: triad.C:255
void operator=(const Vector< vector > &)
Definition: triadI.H:121
uint8_t direction
Definition: direction.H:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Template function to specify if the data of a type are contiguous.
const vector & z() const
Definition: VectorI.H:87
triad()
Construct null.
Definition: triadI.H:28
const vector & y() const
Definition: VectorI.H:81
static const triad I
Definition: triad.H:98
void orthogonalise()
Orthogonalise this triad so that it is ortho-normal.
Definition: triad.C:108
static const triad unset
Definition: triad.H:99
Istream & operator>>(Istream &, directionInfo &)
triad sortxyz() const
Sort the axes such that they are closest to the x, y and z axes.
Definition: triad.C:300
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
const vector & x() const
Definition: VectorI.H:75
Templated 3D Vector derived from VectorSpace adding construction from 3 components, element access using x(), y() and z() member functions and the inner-product (dot-product) and cross product operators.
Definition: Vector.H:57
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static direction primaryDirection(const vector &v)
Return the primary direction of the vector v.
Definition: triadI.H:73
static vector orthogonal(const vector &v1, const vector &v2)
Return the vector orthogonal to the two provided.
Definition: triadI.H:91
Representation of a 3D Cartesian coordinate system as a Vector of vectors.
Definition: triad.H:65
void operator+=(const triad &t2)
Add the triad t2 to this triad.
Definition: triad.C:192
void normalise()
Normalise each set axis vector to have a unit magnitude.
Definition: triadI.H:111
friend Ostream & operator<<(Ostream &, const triad &)
Ostream & operator<<(Ostream &, const ensightPart &)
bool contiguous< triad >()
Data associated with quaternion type are contiguous.
Definition: triad.H:158
Namespace for OpenFOAM.