BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IShape.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Shapes/IShape.cpp
6 //! @brief Implements default methods of interface IShape.
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/IShape.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 IShape::N_Circle = 24;
22 
23 std::vector<kvector_t> IShape::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 / IShape::N_Circle;
40  std::vector<kvector_t> result(IShape::N_Circle);
41  for (size_t i = 0; i < IShape::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 }
std::vector< kvector_t > RectangleVertices(double length, double width, double z)
Helper functions to construct lists of vertices.
Definition: IShape.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: IShape.cpp:37
Defines interface IShape.
#define M_PI
Definition: MathConstants.h:39
BasicVector3D< double > kvector_t
Definition: Vectors3D.h:21
std::vector< kvector_t > m_vertices
List of vertices initialized during construction.
Definition: IShape.h:40
virtual std::vector< kvector_t > vertices() const
Retrieves a list of the vertices constituting this concrete shape.
Definition: IShape.cpp:23
static const size_t N_Circle
Definition: IShape.h:36