triad.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2015 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 zero;
100  static const triad one;
101  static const triad max;
102  static const triad min;
103  static const triad rootMax;
104  static const triad rootMin;
105  static const triad I;
106  static const triad unset;
107 
108 
109  // Member Functions
110 
111  //- Is the vector in the direction d set
112  inline bool set(const direction d) const;
113 
114  //- Are all the vector set
115  inline bool set() const;
116 
117  //- Return the primary direction of the vector v
118  static inline direction primaryDirection(const vector& v);
119 
120  //- Return the vector orthogonal to the two provided
121  static inline vector orthogonal(const vector& v1, const vector& v2);
122 
123  //- Orthogonalize this triad so that it is ortho-normal
124  void orthogonalize();
125 
126  //- Normalize each set axis vector to have a unit magnitude
127  void normalize();
128 
129  //- Align this triad with the given vector v
130  // by rotating the most aligned axis to be coincident with v
131  void align(const vector& v);
132 
133  //- Sort the axes such that they are closest to the x, y and z axes
134  triad sortxyz() const;
135 
136  //- Convert to a quaternion
137  operator quaternion() const;
138 
139 
140  // Member Operators
141 
142  inline void operator=(const Vector<vector>&);
143 
144  void operator=(const tensor& t);
145 
146  //- Add the triad t2 to this triad
147  // without normalizing or orthogonalizing
148  void operator+=(const triad& t2);
149 
150 
151  // IOstream Operators
152 
153  inline friend Istream& operator>>(Istream&, triad&);
154  inline friend Ostream& operator<<(Ostream&, const triad&);
155 };
156 
157 
158 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
159 
160 //- Return a quantity of the difference between two triads
161 scalar diff(const triad& A, const triad& B);
162 
163 //- Data associated with quaternion type are contiguous
164 template<>
165 inline bool contiguous<triad>() {return true;}
166 
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 } // End namespace Foam
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 #include "triadI.H"
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 #endif
179 
180 // ************************************************************************* //
friend Istream & operator>>(Istream &, triad &)
void align(const vector &v)
Align this triad with the given vector v.
Definition: triad.C:259
unsigned char direction
Definition: direction.H:43
static const triad I
Definition: triad.H:104
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:407
friend Ostream & operator<<(Ostream &, const triad &)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
static const triad rootMin
Definition: triad.H:103
triad sortxyz() const
Sort the axes such that they are closest to the x, y and z axes.
Definition: triad.C:304
static direction primaryDirection(const vector &v)
Return the primary direction of the vector v.
Definition: triadI.H:73
triad()
Construct null.
Definition: triadI.H:28
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
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
Namespace for OpenFOAM.
static const triad one
Definition: triad.H:99
void operator+=(const triad &t2)
Add the triad t2 to this triad.
Definition: triad.C:196
static const triad zero
Definition: triad.H:98
const vector & y() const
bool contiguous< triad >()
Data associated with quaternion type are contiguous.
Definition: triad.H:164
static vector orthogonal(const vector &v1, const vector &v2)
Return the vector orthogonal to the two provided.
Definition: triadI.H:91
static const triad min
Definition: triad.H:101
const vector & x() const
void operator=(const Vector< vector > &)
Definition: triadI.H:121
Representation of a 3D Cartesian coordinate system as a Vector of vectors.
Definition: triad.H:65
const vector & z() const
static const triad unset
Definition: triad.H:105
Template function to specify if the data of a type are contiguous.
static const triad max
Definition: triad.H:100
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void orthogonalize()
Orthogonalize this triad so that it is ortho-normal.
Definition: triad.C:121
void normalize()
Normalize each set axis vector to have a unit magnitude.
Definition: triadI.H:111
static const triad rootMax
Definition: triad.H:102