septernion.C
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) 2011-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 \*---------------------------------------------------------------------------*/
25 
26 #include "septernion.H"
27 #include "IOstreams.H"
28 #include "OStringStream.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 const char* const Foam::septernion::typeName = "septernion";
34 (
35  vector(0, 0, 0),
36  quaternion(0, vector(0, 0, 0))
37 );
39 (
40  vector(0, 0, 0),
41  quaternion(1, vector(0, 0, 0))
42 );
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 {
48  is >> *this;
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
55 {
56  OStringStream buf;
57  buf << '(' << s.t() << ',' << s.r() << ')';
58  return buf.str();
59 }
60 
61 
63 (
64  const septernion& sa,
65  const septernion& sb,
66  const scalar t
67 )
68 {
69  return septernion((1 - t)*sa.t() + t*sb.t(), slerp(sa.r(), sb.r(), t));
70 }
71 
72 
74 (
75  const UList<septernion>& ss,
76  const UList<scalar> w
77 )
78 {
79  septernion sa(w[0]*ss[0]);
80 
81  for (label i=1; i<ss.size(); i++)
82  {
83  sa.t() += w[i]*ss[i].t();
84 
85  // Invert quaternion if it has the opposite sign to the average
86  if ((sa.r() & ss[i].r()) > 0)
87  {
88  sa.r() += w[i]*ss[i].r();
89  }
90  else
91  {
92  sa.r() -= w[i]*ss[i].r();
93  }
94  }
95 
96  sa.r().normalise();
97 
98  return sa;
99 }
100 
101 
102 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
103 
105 {
106  // Read beginning of septernion
107  is.readBegin("septernion");
108 
109  is >> s.t() >> s.r();
110 
111  // Read end of septernion
112  is.readEnd("septernion");
113 
114  // Check state of Istream
115  is.check("operator>>(Istream&, septernion&)");
116 
117  return is;
118 }
119 
120 
122 {
123  os << token::BEGIN_LIST
124  << s.t() << token::SPACE << s.r()
125  << token::END_LIST;
126 
127  return os;
128 }
129 
130 
131 // ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:66
const quaternion & r() const
Definition: septernionI.H:64
static const septernion zero
Definition: septernion.H:82
static const septernion I
Definition: septernion.H:83
septernion()
Construct null.
Definition: septernionI.H:28
const vector & t() const
Definition: septernionI.H:58
static const char *const typeName
Definition: septernion.H:80
@ BEGIN_LIST
Definition: token.H:109
@ END_LIST
Definition: token.H:110
A class for handling words, derived from string.
Definition: word.H:62
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Istream & operator>>(Istream &, pistonPointEdgeData &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
quaternion slerp(const quaternion &qa, const quaternion &qb, const scalar t)
Spherical linear interpolation of quaternions.
Definition: quaternion.C:55