BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IShape3D.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Shapes/IShape3D.cpp
6 //! @brief Implements default methods of interface IShape3D.
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 "Sample/Shapes/IShape3D.h"
16 
17 #include <cmath>
18 
19 // Value of 24 ensures that real points stick out of the convex hull at most
20 // 1% of the radius
21 const size_t IShape3D::N_Circle = 24;
22 
23 std::vector<kvector_t> IShape3D::vertices() const
24 {
25  return m_vertices;
26 }
27 
28 std::vector<kvector_t> RectangleVertices(double length, double width, double z)
29 {
30  std::vector<kvector_t> result = {{length / 2.0, width / 2.0, z},
31  {-length / 2.0, width / 2.0, z},
32  {-length / 2.0, -width / 2.0, z},
33  {length / 2.0, -width / 2.0, z}};
34  return result;
35 }
36 
37 std::vector<kvector_t> EllipseVertices(double r_x, double r_y, double z)
38 {
39  static constexpr double delta_angle = 2.0 * M_PI / IShape3D::N_Circle;
40  std::vector<kvector_t> result(IShape3D::N_Circle);
41  for (size_t i = 0; i < IShape3D::N_Circle; ++i) {
42  double angle = i * delta_angle;
43  double x = r_x * std::cos(angle);
44  double y = r_y * std::sin(angle);
45  result[i] = kvector_t(x, y, z);
46  }
47  return result;
48 }
#define M_PI
Definition: Constants.h:44
std::vector< kvector_t > RectangleVertices(double length, double width, double z)
Helper functions to construct lists of vertices.
Definition: IShape3D.cpp:28
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: IShape3D.cpp:37
Defines interface IShape3D.
BasicVector3D< double > kvector_t
Definition: Vectors3D.h:21
virtual std::vector< kvector_t > vertices() const
Retrieves a list of the vertices constituting this concrete shape.
Definition: IShape3D.cpp:23
static const size_t N_Circle
Definition: IShape3D.h:40
std::vector< kvector_t > m_vertices
List of vertices initialized during construction.
Definition: IShape3D.h:44