BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Ellipse.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Mask/Ellipse.cpp
6 //! @brief Implements class Ellipse.
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 "Device/Mask/Ellipse.h"
16 #include "Base/Axis/Bin.h"
17 #include "Base/Types/Exceptions.h"
18 
19 //! @param xcenter x-coordinate of Ellipse's center
20 //! @param ycenter y-coordinate of Ellipse's center
21 //! @param xradius Radius along x-axis
22 //! @param yradius Radius along y-axis
23 //! @param theta Angle of Ellipse rotation in radians
24 Ellipse::Ellipse(double xcenter, double ycenter, double xradius, double yradius, double theta)
25  : IShape2D("Ellipse"), m_xc(xcenter), m_yc(ycenter), m_xr(xradius), m_yr(yradius),
26  m_theta(theta)
27 {
28  if (xradius <= 0.0 || yradius <= 0.0)
30  "Ellipse::Ellipse(double xcenter, double ycenter, double xradius, double yradius) "
31  "-> Error. Radius can't be negative\n");
32 }
33 
34 bool Ellipse::contains(double x, double y) const
35 {
36  double u = std::cos(m_theta) * (x - m_xc) + std::sin(m_theta) * (y - m_yc);
37  double v = -std::sin(m_theta) * (x - m_xc) + std::cos(m_theta) * (y - m_yc);
38  double d = (u / m_xr) * (u / m_xr) + (v / m_yr) * (v / m_yr);
39  return d <= 1;
40 }
41 
42 //! Returns true if area defined by two bins is inside or on border of ellipse;
43 //! more precisely, if mid point of two bins satisfy this condition.
44 bool Ellipse::contains(const Bin1D& binx, const Bin1D& biny) const
45 {
46  return contains(binx.getMidPoint(), biny.getMidPoint());
47 }
Defines structs Bin1D, Bin1DCVector.
Defines class Rectangle.
Defines many exception classes in namespace Exceptionss.
double m_xc
Definition: Ellipse.h:39
double m_xr
Definition: Ellipse.h:39
bool contains(double x, double y) const
Returns true if point with given coordinates is inside or on border of the shape.
Definition: Ellipse.cpp:34
double m_yc
Definition: Ellipse.h:39
double m_yr
Definition: Ellipse.h:39
Ellipse(double xcenter, double ycenter, double xradius, double yradius, double theta=0.0)
Definition: Ellipse.cpp:24
double m_theta
Definition: Ellipse.h:39
Basic class for all shapes in 2D.
Definition: IShape2D.h:27
Definition: Bin.h:20
double getMidPoint() const
Definition: Bin.h:25