11 const double lx,
const double ly,
const double hz,
13 :
Solid(cx, cy, cz,
"SolidRidge"),
20 const double lx,
const double ly,
const double hz,
22 const double dx,
const double dy,
const double dz)
30 double u = x, v = y, w = z;
34 if (fabs(u) > m_lX || fabs(v) > m_lY || w < 0. || w > m_hz) {
36 }
else if (u >= m_hx && m_hz * u + (m_lX - m_hx) * v > m_hz * m_lX) {
38 }
else if (u <= m_hx && -m_hz * u + (m_lX + m_hx) * v > m_hz * m_lX) {
45 double& xmax,
double& ymax,
double& zmax)
const {
56 const double dd = sqrt(m_lX * m_lX + m_lY * m_lY + m_hz * m_hz);
68 std::cerr <<
"SolidRidge::SetHalfLengthX: Half-length must be > 0.\n";
76 std::cerr <<
"SolidRidge::SetHalfLengthY: Half-length must be > 0.\n";
84 std::cerr <<
"SolidRidge::SetRidgeHeight: Height must be > 0.\n";
91 const auto id =
GetId();
92 const unsigned int nPanels = panels.size();
96 std::cerr <<
"SolidRidge::SolidPanels:\n"
97 <<
" Zero norm direction vector; no panels generated.\n";
100 double xv0, yv0, zv0;
101 double xv1, yv1, zv1;
102 double xv2, yv2, zv2;
103 double xv3, yv3, zv3;
106 ToGlobal(-m_lX, -m_lY, 0, xv0, yv0, zv0);
107 ToGlobal(-m_lX, +m_lY, 0, xv1, yv1, zv1);
108 ToGlobal(+m_lX, +m_lY, 0, xv2, yv2, zv2);
109 ToGlobal(+m_lX, -m_lY, 0, xv3, yv3, zv3);
115 base.
xv = {xv0, xv1, xv2, xv3};
116 base.
yv = {yv0, yv1, yv2, yv3};
117 base.
zv = {zv0, zv1, zv2, zv3};
120 panels.push_back(std::move(base));
123 for (
unsigned int i = 0; i < 2; ++i) {
124 const double y = i == 0 ? -m_lY : +m_lY;
125 ToGlobal(-m_lX, y, 0, xv0, yv0, zv0);
126 ToGlobal(+m_lX, y, 0, xv1, yv1, zv1);
127 ToGlobal(m_hx, y, m_hz, xv2, yv2, zv2);
135 side.
xv = {xv0, xv1, xv2};
136 side.
yv = {yv0, yv1, yv2};
137 side.
zv = {zv0, zv1, zv2};
140 panels.push_back(std::move(side));
144 for (
unsigned int i = 0; i < 2; ++i) {
145 const double x = i == 0 ? +m_lX : -m_lX;
146 ToGlobal(x, -m_lY, 0, xv0, yv0, zv0);
147 ToGlobal(x, +m_lY, 0, xv1, yv1, zv1);
148 ToGlobal(m_hx, +m_lY, m_hz, xv2, yv2, zv2);
149 ToGlobal(m_hx, -m_lY, m_hz, xv3, yv3, zv3);
150 const double dx = i == 0 ? m_lX - m_hx : m_lX + m_hx;
151 const double s = sqrt(m_hz * m_hz + dx * dx);
152 const double xroof = i == 0 ? m_hz / s : -m_hz / s;
153 const double zroof = dx / s;
159 roof.
xv = {xv0, xv1, xv2, xv3};
160 roof.
yv = {yv0, yv1, yv2, yv3};
161 roof.
zv = {zv0, zv1, zv2, zv3};
164 panels.push_back(std::move(roof));
166 std::cout <<
"SolidRidge::SolidPanels: " << panels.size() - nPanels
174 double u = 0., v = 0., w = 0.;
177 if (v > std::max(std::abs(u), std::abs(w))) {
179 }
else if (v < -std::max(std::abs(u), std::abs(w))) {
181 }
else if (w < -std::max(std::abs(u), std::abs(v))) {
189 std::cout <<
m_className <<
"::GetDiscretisationLevel:\n"
190 <<
" Found no match for the panel; return first value.\n";
196 const double xn,
const double yn,
const double zn,
197 std::vector<Panel>& panels) {
203 std::vector<double> xv;
204 std::vector<double> yv;
205 std::vector<double> zv;
209 ToGlobal(-m_lX, -m_lY, 0., x1, y1, z1);
211 ToGlobal(+m_lX, -m_lY, 0., x2, y2, z2);
213 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
219 ToGlobal(-m_lX, +m_lY, 0., x2, y2, z2);
220 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
226 ToGlobal(m_hx, -m_lY, m_hz, x2, y2, z2);
227 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
234 ToGlobal(+m_lX, +m_lY, 0., x1, y1, z1);
235 ToGlobal(-m_lX, +m_lY, 0., x2, y2, z2);
236 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
243 ToGlobal(+m_lX, -m_lY, 0., x2, y2, z2);
244 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
251 ToGlobal(m_hx, +m_lY, m_hz, x2, y2, z2);
252 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
259 ToGlobal(-m_lX, +m_lY, 0., x1, y1, z1);
260 ToGlobal(m_hx, +m_lY, m_hz, x2, y2, z2);
261 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
268 ToGlobal(m_hx, +m_lY, m_hz, x1, y1, z1);
269 ToGlobal(m_hx, -m_lY, m_hz, x2, y2, z2);
270 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
277 ToGlobal(m_hx, -m_lY, m_hz, x1, y1, z1);
278 ToGlobal(+m_lX, -m_lY, 0., x2, y2, z2);
279 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
287 if (xv.size() >= 3) {
297 panels.push_back(std::move(panel));
Triangular prism (Toblerone bar).
SolidRidge(const double cx, const double cy, const double cz, const double lx, const double ly, const double hz, const double offsetx)
Constructor from centre, half-lengths, height and x-offset.
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const override
Return the bounding box of the solid.
void SetRidgeHeight(const double hz)
Set the height of the ridge.
double GetDiscretisationLevel(const Panel &panel) override
Retrieve the discretisation level of a panel.
bool IsInside(const double x, const double y, const double z, const bool tesselated) const override
void SetHalfLengthX(const double lx)
Set the half-length along x.
bool SolidPanels(std::vector< Panel > &panels) override
Retrieve the surface panels of the solid.
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)
Set the half-length along y.
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)
double m_dX
Direction vector.
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.