BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
dodecahedron.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/ba3d/mesh/dodecahedron.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  const float GR = GoldenRatio, G1 = 1 / GR;
25 
26  Vertices vs_;
27  vs_.reserve(20);
28  for (float x : {-1, +1})
29  for (float y : {-1, +1})
30  for (float z : {-1, +1})
31  vs_.append(Vector3D(x, y, z));
32 
33  for (float g1 : {-G1, +G1})
34  for (float g : {-GR, +GR}) {
35  vs_.append(Vector3D(0, g1, g));
36  vs_.append(Vector3D(g1, g, 0));
37  vs_.append(Vector3D(g, 0, g1));
38  }
39 
40  ASSERT(20 == vs_.count());
41 
42  // scale to circumscribed sphere
43  float const F = .5f / vs_.at(0).length();
44  for (auto& v : vs_)
45  v = v * F;
46 
47  // face down
48  auto q = QQuaternion::rotationTo(-Vector3D::_z,
49  cross(vs_.at(8) - vs_.at(0), vs_.at(10) - vs_.at(0)));
50  for (int i = 0; i < 20; ++i) {
51  vs_[i] = q.rotatedVector(vs_.at(i));
52  vs_[i].z += 0.5f * std::sqrt(G1); // shift the bottom of the dodecahedron to z=0 plane
53  }
54 
55  Vertices vs;
56  vs.reserve(180);
57 
58  auto add5 = [&](unsigned i1, unsigned i2, unsigned i3, unsigned i4, unsigned i5) {
59  vs.addFan(vs_, {i1, i2, i3, i4, i5, i1});
60  };
61 
62  add5(1, 11, 17, 3, 16); // bottom
63  add5(1, 16, 10, 0, 9);
64  add5(16, 3, 12, 2, 10);
65  add5(3, 17, 7, 18, 12);
66  add5(17, 11, 5, 19, 7);
67  add5(11, 1, 9, 15, 5);
68 
69  add5(8, 4, 15, 9, 0);
70  add5(14, 8, 0, 10, 2);
71  add5(6, 14, 2, 12, 18);
72  add5(13, 6, 18, 7, 19);
73  add5(4, 13, 19, 5, 15);
74  add5(4, 8, 14, 6, 13); // top
75 
76  ASSERT(144 == vs.count());
77 
78  return makeMesh(vs);
79 }
80 
81 } // 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 meshDodecahedron()
Defines Geometry class.
Vector3D cross(const Vector3D &v1, const Vector3D &v2)
Definition: def.cpp:67
const float GoldenRatio
void addFan(const Vertices &, const Indices &)
Definition: geometry.cpp:65
static Vector3D const _z
Definition: def.h:46