BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
cuboctahedron.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/ba3d/mesh/cuboctahedron.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 <qmath.h>
18 
19 namespace GUI::RealSpace {
20 
21 Geometry::Mesh Geometry::meshBipyramid4(float rH, float alpha, float H)
22 { // t/D
23 
24  // alpha is the angle between the common square interface and one of the side faces (alpha for
25  // both the two truncated pyramids is the same)
26 
27  // H here is the normalized height of the cuboctahedron i.e. H/L (see particles.cpp)
28 
29  ASSERT(alpha <= float(M_PI_2));
30  ASSERT(rH >= 0);
31 
32  float const D = .5f, t = tanf(float(M_PI_2) - alpha);
33  float const Db = D - t * H, Dt = D - t * rH * H;
34 
35  Vertices vs_;
36  vs_.reserve(12);
37  float z[] = {0, H, H * (rH + 1)},
38  d[] = {Db, D, Dt}; // keep bottom of the cuboctahedron in z=0 plane
39  for (int i = 0; i < 3; ++i)
40  for (int x : {-1, +1})
41  for (int y : {-1, +1}) {
42  float di = d[i];
43  vs_.append(Vector3D(x * di, y * di, z[i]));
44  }
45 
46  ASSERT(12 == vs_.count());
47 
48  Vertices vs;
49  vs.reserve(60);
50 
51  vs.addQuad(vs_, 0, 1, 3, 2);
52  vs.addQuad(vs_, 8, 10, 11, 9);
53  vs.addQuad(vs_, 0, 4, 5, 1);
54  vs.addQuad(vs_, 1, 5, 7, 3);
55  vs.addQuad(vs_, 3, 7, 6, 2);
56  vs.addQuad(vs_, 2, 6, 4, 0);
57  vs.addQuad(vs_, 4, 8, 9, 5);
58  vs.addQuad(vs_, 5, 9, 11, 7);
59  vs.addQuad(vs_, 7, 11, 10, 6);
60  vs.addQuad(vs_, 6, 10, 8, 4);
61 
62  ASSERT(60 == vs.count());
63 
64  return makeMesh(vs);
65 }
66 
67 } // 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 meshBipyramid4(float rH, float alpha, float H)
Defines Geometry class.
void addQuad(const Vector3D &, const Vector3D &, const Vector3D &, const Vector3D &)
Definition: geometry.cpp:42