BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
TruncatedEllipsoidNet.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Shapes/TruncatedEllipsoidNet.cpp
6 //! @brief Implements class TruncatedEllipsoidNet.
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 
16 
17 #include <algorithm>
18 #include <cmath>
19 
20 TruncatedEllipsoidNet::TruncatedEllipsoidNet(double r_x, double r_y, double r_z, double height,
21  double dh)
22 {
23  static const int n_heights =
24  std::max(2, static_cast<int>(std::round(
25  static_cast<double>(IShape3D::N_Circle) * height / 2.0 / r_z + 0.5)));
26  double h_step = (height - dh) / (n_heights - 1);
27  m_vertices.resize(n_heights * IShape3D::N_Circle);
28  auto it = m_vertices.begin();
29  for (int i = 0; i < n_heights; ++i) {
30  double z = i * h_step;
31  double radius_factor = std::sqrt(1.0 - std::pow((z + r_z - height) / r_z, 2));
32  auto ellipse = EllipseVerticesZ(radius_factor * r_x, radius_factor * r_y, i * h_step);
33  std::move(ellipse.begin(), ellipse.end(), it);
34  it = it + ellipse.size();
35  }
36 }
37 
std::vector< R3 > EllipseVerticesZ(double r_x, double r_y, double z)
Generate vertices of centered horizontal ellipse with given semi-axes at height z.
Definition: IShape3D.cpp:37
Defines class TruncatedEllipsoidNet.
std::vector< R3 > m_vertices
List of vertices initialized during construction.
Definition: IShape3D.h:42
static const size_t N_Circle
Definition: IShape3D.h:38
TruncatedEllipsoidNet(double r_x, double r_y, double r_z, double height, double dh)
~TruncatedEllipsoidNet() override