12 const double lx,
const double ly,
const double lz)
13 :
Solid(cx, cy, cz,
"SolidBox"), m_lX(lx), m_lY(ly), m_lZ(lz) {}
16 const double lx,
const double ly,
const double lz,
17 const double dx,
const double dy,
const double dz)
25 double u = x, v = y, w = z;
29 if (fabs(u) > m_lX || fabs(v) > m_lY || fabs(w) > m_lZ) {
36 double& xmax,
double& ymax,
double& zmax)
const {
47 const double dd = sqrt(m_lX * m_lX + m_lY * m_lY + m_lZ * m_lZ);
61 std::cerr <<
"SolidBox::SetHalfLengthX: Half-length must be > 0.\n";
69 std::cerr <<
"SolidBox::SetHalfLengthY: Half-length must be > 0.\n";
77 std::cerr <<
"SolidBox::SetHalfLengthZ: Half-length must be > 0.\n";
82 const auto id =
GetId();
83 const auto nPanels = panels.size();
89 if (m_lY > 0 && m_lZ > 0) {
90 ToGlobal(-m_lX, -m_lY, -m_lZ, xv0, yv0, zv0);
91 ToGlobal(-m_lX, +m_lY, -m_lZ, xv1, yv1, zv1);
92 ToGlobal(-m_lX, +m_lY, +m_lZ, xv2, yv2, zv2);
93 ToGlobal(-m_lX, -m_lY, +m_lZ, xv3, yv3, zv3);
98 panel.
xv = {xv0, xv1, xv2, xv3};
99 panel.
yv = {yv0, yv1, yv2, yv3};
100 panel.
zv = {zv0, zv1, zv2, zv3};
103 panels.push_back(std::move(panel));
106 if (m_lX > 0 && m_lY > 0 && m_lZ > 0) {
107 ToGlobal(+m_lX, -m_lY, -m_lZ, xv0, yv0, zv0);
108 ToGlobal(+m_lX, +m_lY, -m_lZ, xv1, yv1, zv1);
109 ToGlobal(+m_lX, +m_lY, +m_lZ, xv2, yv2, zv2);
110 ToGlobal(+m_lX, -m_lY, +m_lZ, xv3, yv3, zv3);
115 panel.
xv = {xv0, xv1, xv2, xv3};
116 panel.
yv = {yv0, yv1, yv2, yv3};
117 panel.
zv = {zv0, zv1, zv2, zv3};
120 panels.push_back(std::move(panel));
123 if (m_lX > 0 && m_lZ > 0) {
124 ToGlobal(-m_lX, -m_lY, -m_lZ, xv0, yv0, zv0);
125 ToGlobal(+m_lX, -m_lY, -m_lZ, xv1, yv1, zv1);
126 ToGlobal(+m_lX, -m_lY, +m_lZ, xv2, yv2, zv2);
127 ToGlobal(-m_lX, -m_lY, +m_lZ, xv3, yv3, zv3);
132 panel.
xv = {xv0, xv1, xv2, xv3};
133 panel.
yv = {yv0, yv1, yv2, yv3};
134 panel.
zv = {zv0, zv1, zv2, zv3};
137 panels.push_back(std::move(panel));
140 if (m_lX > 0 && m_lY > 0 && m_lZ > 0) {
141 ToGlobal(-m_lX, +m_lY, -m_lZ, xv0, yv0, zv0);
142 ToGlobal(+m_lX, +m_lY, -m_lZ, xv1, yv1, zv1);
143 ToGlobal(+m_lX, +m_lY, +m_lZ, xv2, yv2, zv2);
144 ToGlobal(-m_lX, +m_lY, +m_lZ, xv3, yv3, zv3);
149 panel.
xv = {xv0, xv1, xv2, xv3};
150 panel.
yv = {yv0, yv1, yv2, yv3};
151 panel.
zv = {zv0, zv1, zv2, zv3};
154 panels.push_back(std::move(panel));
157 if (m_lX > 0 && m_lY > 0) {
158 ToGlobal(-m_lX, -m_lY, -m_lZ, xv0, yv0, zv0);
159 ToGlobal(-m_lX, +m_lY, -m_lZ, xv1, yv1, zv1);
160 ToGlobal(+m_lX, +m_lY, -m_lZ, xv2, yv2, zv2);
161 ToGlobal(+m_lX, -m_lY, -m_lZ, xv3, yv3, zv3);
166 panel.
xv = {xv0, xv1, xv2, xv3};
167 panel.
yv = {yv0, yv1, yv2, yv3};
168 panel.
zv = {zv0, zv1, zv2, zv3};
171 panels.push_back(std::move(panel));
174 if (m_lX > 0 && m_lY > 0 && m_lZ > 0) {
175 ToGlobal(-m_lX, -m_lY, +m_lZ, xv0, yv0, zv0);
176 ToGlobal(-m_lX, +m_lY, +m_lZ, xv1, yv1, zv1);
177 ToGlobal(+m_lX, +m_lY, +m_lZ, xv2, yv2, zv2);
178 ToGlobal(+m_lX, -m_lY, +m_lZ, xv3, yv3, zv3);
183 panel.
xv = {xv0, xv1, xv2, xv3};
184 panel.
yv = {yv0, yv1, yv2, yv3};
185 panel.
zv = {zv0, zv1, zv2, zv3};
188 panels.push_back(std::move(panel));
191 std::cout <<
"SolidBox::SolidPanels: " << panels.size() - nPanels
199 double u = 0., v = 0., w = 0.;
202 if (u > std::max(std::abs(v), std::abs(w))) {
204 }
else if (u < -std::max(std::abs(v), std::abs(w))) {
206 }
else if (v > std::max(std::abs(u), std::abs(w))) {
208 }
else if (v < -std::max(std::abs(u), std::abs(w))) {
210 }
else if (w > std::max(std::abs(u), std::abs(v))) {
212 }
else if (w < -std::max(std::abs(u), std::abs(v))) {
216 std::cout <<
m_className <<
"::GetDiscretisationLevel:\n"
217 <<
" Found no match for the panel; return first value.\n";
223 const double xn,
const double yn,
const double zn,
224 std::vector<Panel>& panels) {
230 std::vector<double> xv;
231 std::vector<double> yv;
232 std::vector<double> zv;
236 ToGlobal(-m_lX, -m_lY, -m_lZ, x1, y1, z1);
238 ToGlobal(+m_lX, -m_lY, -m_lZ, x2, y2, z2);
240 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
246 ToGlobal(-m_lX, +m_lY, -m_lZ, x2, y2, z2);
247 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
253 ToGlobal(-m_lX, -m_lY, +m_lZ, x2, y2, z2);
254 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
260 ToGlobal(+m_lX, +m_lY, -m_lZ, x1, y1, z1);
261 ToGlobal(-m_lX, +m_lY, -m_lZ, x2, y2, z2);
262 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
268 ToGlobal(+m_lX, -m_lY, -m_lZ, x2, y2, z2);
269 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
275 ToGlobal(+m_lX, +m_lY, +m_lZ, x2, y2, z2);
276 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
282 ToGlobal(-m_lX, +m_lY, +m_lZ, x1, y1, z1);
283 ToGlobal(+m_lX, +m_lY, +m_lZ, x2, y2, z2);
284 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
290 ToGlobal(-m_lX, -m_lY, +m_lZ, x2, y2, z2);
291 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
297 ToGlobal(-m_lX, +m_lY, -m_lZ, x1, y1, z1);
298 ToGlobal(-m_lX, +m_lY, +m_lZ, x2, y2, z2);
299 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
305 ToGlobal(+m_lX, -m_lY, +m_lZ, x1, y1, z1);
306 ToGlobal(-m_lX, -m_lY, +m_lZ, x2, y2, z2);
307 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
313 ToGlobal(+m_lX, +m_lY, +m_lZ, x2, y2, z2);
314 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
320 ToGlobal(+m_lX, -m_lY, -m_lZ, x2, y2, z2);
321 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
329 if (xv.size() >= 3) {
339 panels.push_back(std::move(panel));
void SetHalfLengthX(const double lx)
SolidBox(const double cx, const double cy, const double cz, const double lx, const double ly, const double lz)
Constructor from centre and half-widths.
bool SolidPanels(std::vector< Panel > &panels) override
Retrieve the surface panels of the solid.
bool IsInside(const double x, const double y, const double z, const bool tesselated) const override
void SetHalfLengthZ(const double lz)
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const override
Return the bounding box of the solid.
double GetDiscretisationLevel(const Panel &panel) override
Retrieve the discretisation level of a panel.
void Cut(const double x0, const double y0, const double z0, const double xn, const double yn, const double zn, std::vector< Panel > &panels) override
void SetHalfLengthY(const double ly)
Abstract base class for solids.
void VectorToLocal(const double x, const double y, const double z, double &u, double &v, double &w)
Transform a vector from global to local coordinates.
double m_cTheta
Polar angle.
static bool Intersect(const double x1, const double y1, const double z1, const double x2, const double y2, const double z2, const double x0, const double y0, const double z0, const double a, const double b, const double c, double &xc, double &yc, double &zc)
unsigned int GetId() const
Get the ID of the solid.
void ToLocal(const double x, const double y, const double z, double &u, double &v, double &w) const
void SetDirection(const double dx, const double dy, const double dz)
void ToGlobal(const double u, const double v, const double w, double &x, double &y, double &z) const
double m_cX
Centre of the solid.
double m_cPhi
Azimuthal angle.
std::string m_className
Class name.
void EliminateButterflies(std::vector< double > &xp, std::vector< double > &yp, std::vector< double > &zp)
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.