BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
TruncatedEllipsoid.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Shapes/TruncatedEllipsoid.cpp
6 //! @brief Implements class TruncatedEllipsoid.
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 TruncatedEllipsoid::TruncatedEllipsoid(double r_x, double r_y, double r_z, double height, double dh)
21 {
22  static const int n_heights =
23  std::max(2, static_cast<int>(std::round(
24  static_cast<double>(IShape::N_Circle) * height / 2.0 / r_z + 0.5)));
25  double h_step = (height - dh) / (n_heights - 1);
26  m_vertices.resize(n_heights * IShape::N_Circle);
27  auto it = m_vertices.begin();
28  for (int i = 0; i < n_heights; ++i) {
29  double z = i * h_step;
30  double radius_factor = std::sqrt(1.0 - std::pow((z + r_z - height) / r_z, 2));
31  auto ellipse = EllipseVertices(radius_factor * r_x, radius_factor * r_y, i * h_step);
32  std::move(ellipse.begin(), ellipse.end(), it);
33  it = it + ellipse.size();
34  }
35 }
36 
std::vector< kvector_t > EllipseVertices(double r_x, double r_y, double z)
Generate vertices of centered ellipse with given semi-axes at height z.
Definition: IShape.cpp:37
Defines class TruncatedEllipsoid.
std::vector< kvector_t > m_vertices
List of vertices initialized during construction.
Definition: IShape.h:40
static const size_t N_Circle
Definition: IShape.h:36
TruncatedEllipsoid(double r_x, double r_y, double r_z, double height, double dh)