BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IShape3D.cpp File Reference

Description

Implements default methods of interface IShape3D.

Homepage:\n http://www.bornagainproject.org
License:\n GNU General Public License v3 or higher (see COPYING)
Authors
Scientific Computing Group at MLZ (see CITATION, AUTHORS)

Definition in file IShape3D.cpp.

Include dependency graph for IShape3D.cpp:

Go to the source code of this file.

Functions

std::vector< R3 > EllipseVerticesXtrunc (double x, double r_y, double r_z, double z_b, double z_t)
 Generate vertices of centered vertical ellipse with given semi-axes at position x and truncation heights z_b (bottom) and z_t (top) More...
 
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. More...
 
std::vector< R3 > RectangleVertices (double length, double width, double z)
 Helper functions to construct lists of vertices. More...
 

Function Documentation

◆ EllipseVerticesXtrunc()

std::vector<R3> EllipseVerticesXtrunc ( double  x,
double  r_y,
double  r_z,
double  z_b,
double  z_t 
)

Generate vertices of centered vertical ellipse with given semi-axes at position x and truncation heights z_b (bottom) and z_t (top)

Definition at line 50 of file IShape3D.cpp.

51 {
52  static constexpr double delta_angle = 2.0 * M_PI / IShape3D::N_Circle;
53  // for full ellipse
54  // std::vector<R3> result(IShape3D::N_Circle);
55  // for (size_t i = 0; i < IShape3D::N_Circle; ++i) {
56  // double angle = i * delta_angle;
57  // double y = r_y * std::cos(angle);
58  // double z = r_z * std::sin(angle) + r_z; // bottom is at 0, top at 2*r_z
59  // result[i] = R3(x, y, z);
60  // }
61 
62  // for truncated ellipse
63  std::vector<R3> result;
64  result.reserve(IShape3D::N_Circle + 4);
65  for (size_t i = 0; i < IShape3D::N_Circle; ++i) {
66  double angle = i * delta_angle;
67  double y = r_y * std::cos(angle);
68  double z = r_z * std::sin(angle) - z_b; // bottom is at 0, top at z_t-z_b
69 
70  if (0 <= z && z <= (z_t - z_b)) {
71  result.push_back(R3(x, y, z));
72  }
73  }
74  double alpha_t = atan(z_t / sqrt(r_z * r_z - z_t * z_t) * r_z / r_y);
75  double alpha_b = atan(z_b / sqrt(r_z * r_z - z_b * z_b) * r_z / r_y);
76 
77  double y_t = r_y * std::cos(alpha_t);
78  double y_b = r_y * std::cos(alpha_b);
79 
80  result.push_back(R3(x, y_t, z_t - z_b));
81  result.push_back(R3(x, -y_t, z_t - z_b));
82  result.push_back(R3(x, y_b, 0));
83  result.push_back(R3(x, -y_b, 0));
84 
85  return result;
86 }
#define M_PI
Definition: Constants.h:44
static const size_t N_Circle
Definition: IShape3D.h:38

References M_PI, and IShape3D::N_Circle.

Referenced by DoubleEllipseX::DoubleEllipseX().

◆ EllipseVerticesZ()

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 at line 37 of file IShape3D.cpp.

38 {
39  static constexpr double delta_angle = 2.0 * M_PI / IShape3D::N_Circle;
40  std::vector<R3> 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] = R3(x, y, z);
46  }
47  return result;
48 }

References M_PI, and IShape3D::N_Circle.

Referenced by DoubleEllipseZ::DoubleEllipseZ(), and TruncatedEllipsoidNet::TruncatedEllipsoidNet().

◆ RectangleVertices()

std::vector<R3> RectangleVertices ( double  length,
double  width,
double  z 
)

Helper functions to construct lists of vertices.

Generate vertices of centered rectangle at height z

Definition at line 28 of file IShape3D.cpp.

29 {
30  std::vector<R3> 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 }

Referenced by BoxNet::BoxNet().