BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
icosahedron.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/ba3d/mesh/icosahedron.cpp
6 //! @brief Implements utility functions in ba3d namespace
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "Base/Util/Assert.h"
17 #include <QQuaternion>
18 #include <qmath.h>
19 
20 namespace GUI::RealSpace {
21 
23 {
24  Vertices vs_(12); // 12 vertices of the icosahedron retrieved from Icosahedron.cpp
25 
26  const float E = 1.0; // edge
27 
28  vs_[0] = Vector3D(-0.57735026918962573f * E, 0.0f * E, 0.0f);
29  vs_[1] = Vector3D(0.28867513459481281f * E, 0.5f * E, 0.0f);
30  vs_[2] = Vector3D(0.28867513459481281f * E, -0.5f * E, 0.0f);
31  vs_[3] = Vector3D(0.93417235896271578f * E, 0.0f * E, 0.57735026918962562f * E);
32  vs_[4] =
33  Vector3D(-0.46708617948135783f * E, 0.80901699437494756f * E, 0.57735026918962562f * E);
34  vs_[5] =
35  Vector3D(-0.46708617948135783f * E, -0.80901699437494756f * E, 0.57735026918962562f * E);
36  vs_[6] = Vector3D(-0.93417235896271578f * E, 0.0f * E, 0.93417235896271589f * E);
37  vs_[7] = Vector3D(0.46708617948135783f * E, 0.80901699437494756f * E, 0.93417235896271589f * E);
38  vs_[8] =
39  Vector3D(0.46708617948135783f * E, -0.80901699437494756f * E, 0.93417235896271589f * E);
40  vs_[9] = Vector3D(0.57735026918962573f * E, 0.0f * E, 1.5115226281523415f * E);
41  vs_[10] = Vector3D(-0.28867513459481281f * E, 0.5f * E, 1.5115226281523415f * E);
42  vs_[11] = Vector3D(-0.28867513459481281f * E, -0.5f * E, 1.5115226281523415f * E);
43 
44  ASSERT(12 == vs_.count());
45 
46  Vertices vs;
47  vs.reserve(60);
48 
49  // lower half of the icosahedron (clockwise ordering of vertices)
50  vs.addTriangle(vs_[0], vs_[1], vs_[2]);
51  vs.addTriangle(vs_[0], vs_[4], vs_[1]);
52  vs.addTriangle(vs_[1], vs_[3], vs_[2]);
53  vs.addTriangle(vs_[2], vs_[5], vs_[0]);
54 
55  vs.addTriangle(vs_[0], vs_[6], vs_[4]);
56  vs.addTriangle(vs_[4], vs_[7], vs_[1]);
57  vs.addTriangle(vs_[1], vs_[7], vs_[3]);
58  vs.addTriangle(vs_[3], vs_[8], vs_[2]);
59  vs.addTriangle(vs_[8], vs_[5], vs_[2]);
60  vs.addTriangle(vs_[5], vs_[6], vs_[0]);
61 
62  // upper half of the icosahedron (couter clockwise ordering of vertices)
63  vs.addTriangle(vs_[11], vs_[6], vs_[5]);
64  vs.addTriangle(vs_[8], vs_[11], vs_[5]);
65  vs.addTriangle(vs_[9], vs_[8], vs_[3]);
66  vs.addTriangle(vs_[9], vs_[3], vs_[7]);
67  vs.addTriangle(vs_[10], vs_[7], vs_[4]);
68  vs.addTriangle(vs_[6], vs_[10], vs_[4]);
69 
70  vs.addTriangle(vs_[10], vs_[6], vs_[11]);
71  vs.addTriangle(vs_[9], vs_[11], vs_[8]);
72  vs.addTriangle(vs_[9], vs_[7], vs_[10]);
73  vs.addTriangle(vs_[9], vs_[10], vs_[11]);
74 
75  ASSERT(60 == vs.count());
76 
77  return makeMesh(vs);
78 }
79 
80 } // namespace GUI::RealSpace
static Mesh makeMesh(const Vertices &vs, Vertices const *ns=nullptr)
Definition: geometry.cpp:117
QVector< Vert_Normal > Mesh
Definition: geometry.h:66
static Mesh meshIcosahedron()
Definition: icosahedron.cpp:22
Defines Geometry class.
void addTriangle(const Vector3D &, const Vector3D &, const Vector3D &)
Definition: geometry.cpp:35