12 :
Solid(cx, cy, cz,
"SolidSphere") {
17 const double z)
const {
19 const double dx = x -
m_cX;
20 const double dy = y -
m_cY;
21 const double dz = z -
m_cZ;
23 if (fabs(dx) > m_r || fabs(dy) > m_r || fabs(dz) > m_r) {
25 std::cout <<
"SolidSphere::IsInside: (" << x <<
", " << y <<
", " << z
31 const double r = sqrt(dx * dx + dy * dy + dz * dz);
34 std::cout <<
"SolidSphere::IsInside: (" << x <<
", " << y <<
", " << z
41 std::cout <<
"SolidSphere::IsInside: (" << x <<
", " << y <<
", " << z
48 double& xmax,
double& ymax,
61 std::cerr <<
"SolidSphere::SetRadius: Radius must be > 0.\n";
69 std::cerr <<
"SolidSphere::SetMeridians: Number must be >= 3.\n";
76 const auto id =
GetId();
77 const unsigned int nPanels = panels.size();
79 for (
unsigned int i = 1; i <= m_n; ++i) {
80 const double phi0 = TwoPi * (i - 1.) / m_n;
81 const double phi1 = TwoPi * double(i) / m_n;
82 const double cphi0 = cos(phi0);
83 const double sphi0 = sin(phi0);
84 const double cphi1 = cos(phi1);
85 const double sphi1 = sin(phi1);
86 for (
unsigned int j = 1; j <= m_n; ++j) {
87 const double theta0 = -HalfPi + Pi * (j - 1.) / m_n;
88 const double theta1 = -HalfPi + Pi * double(j) / m_n;
89 const double ctheta0 = cos(theta0);
90 const double stheta0 = sin(theta0);
91 const double ctheta1 = cos(theta1);
92 const double stheta1 = sin(theta1);
96 const double xv0 =
m_cX + m_r * cphi0 * ctheta0;
97 const double yv0 =
m_cY + m_r * sphi0 * ctheta0;
98 const double zv0 =
m_cZ + m_r * stheta0;
99 const double xv1 =
m_cX + m_r * cphi1 * ctheta1;
100 const double yv1 =
m_cY + m_r * sphi1 * ctheta1;
101 const double zv1 =
m_cZ + m_r * stheta1;
102 const double xv2 =
m_cX + m_r * cphi0 * ctheta1;
103 const double yv2 =
m_cY + m_r * sphi0 * ctheta1;
104 const double zv2 =
m_cZ + m_r * stheta1;
105 newpanel.
xv = {xv0, xv1, xv2};
106 newpanel.
yv = {yv0, yv1, yv2};
107 newpanel.
zv = {zv0, zv1, zv2};
108 }
else if (j == m_n) {
109 const double xv0 =
m_cX + m_r * cphi0 * ctheta0;
110 const double yv0 =
m_cY + m_r * sphi0 * ctheta0;
111 const double zv0 =
m_cZ + m_r * stheta0;
112 const double xv1 =
m_cX + m_r * cphi1 * ctheta0;
113 const double yv1 =
m_cY + m_r * sphi1 * ctheta0;
114 const double zv1 =
m_cZ + m_r * stheta0;
115 const double xv2 =
m_cX + m_r * cphi1 * ctheta1;
116 const double yv2 =
m_cY + m_r * sphi1 * ctheta1;
117 const double zv2 =
m_cZ + m_r * stheta1;
118 newpanel.
xv = {xv0, xv1, xv2};
119 newpanel.
yv = {yv0, yv1, yv2};
120 newpanel.
zv = {zv0, zv1, zv2};
122 const double xv0 =
m_cX + m_r * cphi0 * ctheta0;
123 const double yv0 =
m_cY + m_r * sphi0 * ctheta0;
124 const double zv0 =
m_cZ + m_r * stheta0;
125 const double xv1 =
m_cX + m_r * cphi1 * ctheta0;
126 const double yv1 =
m_cY + m_r * sphi1 * ctheta0;
127 const double zv1 =
m_cZ + m_r * stheta0;
128 const double xv2 =
m_cX + m_r * cphi1 * ctheta1;
129 const double yv2 =
m_cY + m_r * sphi1 * ctheta1;
130 const double zv2 =
m_cZ + m_r * stheta1;
131 const double xv3 =
m_cX + m_r * cphi0 * ctheta1;
132 const double yv3 =
m_cY + m_r * sphi0 * ctheta1;
133 const double zv3 =
m_cZ + m_r * stheta1;
134 newpanel.
xv = {xv0, xv1, xv2, xv3};
135 newpanel.
yv = {yv0, yv1, yv2, yv3};
136 newpanel.
zv = {zv0, zv1, zv2, zv3};
140 atan2((ctheta0 - ctheta1) * sqrt((1. + cos(phi1 - phi0)) / 2),
142 const double calpha = cos(alpha);
143 const double salpha = sin(alpha);
145 newpanel.
a = cos(0.5 * (phi0 + phi1)) * calpha;
146 newpanel.
b = sin(0.5 * (phi0 + phi1)) * calpha;
149 panels.push_back(std::move(newpanel));
152 std::cout <<
"SolidSphere::SolidPanels: " << panels.size() - nPanels
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const override
Return the bounding box of the solid.
bool IsInside(const double x, const double y, const double z) const override
Check whether a given point is inside the solid.
void SetRadius(const double r)
Set the radius of the sphere.
double GetDiscretisationLevel(const Panel &panel) override
Retrieve the discretization level of a panel.
bool SolidPanels(std::vector< Panel > &panels) override
Retrieve the surface panels of the solid.
SolidSphere(const double cx, const double cy, const double cz, const double r)
Constructor.
void SetMeridians(const unsigned int n)
Abstract base class for solids.
unsigned int GetId() const
Get the ID of the solid.
double m_cX
Centre of the solid.
std::vector< double > zv
Z-coordinates of vertices.
int volume
Reference to solid to which the panel belongs.
double a
Perpendicular vector.
std::vector< double > xv
X-coordinates of vertices.
std::vector< double > yv
Y-coordinates of vertices.