22void validateParams(
double x0,
double y0,
double z0,
double x1,
double y1,
double z1,
double t,
24 constexpr double eps = 1.0e-12;
25 if (!(x1 > x0 + eps && y1 > y0 + eps && z1 > z0 + eps && t > eps))
26 throw std::runtime_error(
27 "OpenCuboidChannel3D: require x0<x1, y0<y1, z0<z1, t>0.");
28 if (!(x1 - x0 > 2. * t + eps && y1 - y0 > 2. * t + eps && z1 - z0 > 2. * t + eps))
29 throw std::runtime_error(
30 "OpenCuboidChannel3D: each outer span must exceed 2*t so the inner cavity exists.");
31 if (open_face < 0 || open_face > 5)
32 throw std::runtime_error(
"OpenCuboidChannel3D: open_face must be in 0..5 (±x,±y,±z).");
36 const double x0 = lo.
d_x, y0 = lo.
d_y, z0 = lo.
d_z;
37 const double x1 = hi.
d_x, y1 = hi.
d_y, z1 = hi.
d_z;
38 out8[0] = {x0, y0, z0};
39 out8[1] = {x1, y0, z0};
40 out8[2] = {x1, y1, z0};
41 out8[3] = {x0, y1, z0};
42 out8[4] = {x0, y0, z1};
43 out8[5] = {x1, y0, z1};
44 out8[6] = {x1, y1, z1};
45 out8[7] = {x0, y1, z1};
50 for (
int i = 1; i < 8; ++i) {
66 double t,
int open_face, std::string description)
67 :
GeomObject(
"open_cuboid_channel_3d", std::move(description)),
71 d_openFace(open_face) {
72 validateParams(x0, y0, z0, x1, y1, z1, t, open_face);
77 :
GeomObject(other.d_name, other.d_description),
81 d_openFace(other.d_openFace),
101 const auto &L =
d_lo;
102 const auto &H =
d_hi;
103 const double t =
d_t;
104 const bool in_outer =
105 p.
d_x >= L.d_x && p.
d_x <= H.d_x && p.
d_y >= L.d_y && p.
d_y <= H.d_y && p.
d_z >= L.d_z &&
107 const double xi0 = L.d_x + t, xi1 = H.d_x - t;
108 const double yi0 = L.d_y + t, yi1 = H.d_y - t;
109 const double zi0 = L.d_z + t, zi1 = H.d_z - t;
110 const bool in_inner =
111 p.
d_x >= xi0 && p.
d_x <= xi1 && p.
d_y >= yi0 && p.
d_y <= yi1 && p.
d_z >= zi0 && p.
d_z <= zi1;
112 return in_outer && !in_inner;
118 const auto &L =
d_lo;
119 const auto &H =
d_hi;
120 const double t =
d_t;
121 constexpr double eps = 1.0e-12;
122 const double x0 = L.
d_x, y0 = L.d_y, z0 = L.d_z;
123 const double x1 = H.d_x, y1 = H.d_y, z1 = H.d_z;
127 if (p.
d_x < x1 - t - eps || p.
d_x > x1 + eps)
129 const bool oyz = p.
d_y >= y0 && p.
d_y <= y1 && p.
d_z >= z0 && p.
d_z <= z1;
131 p.
d_y >= y0 + t && p.
d_y <= y1 - t && p.
d_z >= z0 + t && p.
d_z <= z1 - t;
135 if (p.
d_x < x0 - eps || p.
d_x > x0 + t + eps)
137 const bool oyz = p.
d_y >= y0 && p.
d_y <= y1 && p.
d_z >= z0 && p.
d_z <= z1;
139 p.
d_y >= y0 + t && p.
d_y <= y1 - t && p.
d_z >= z0 + t && p.
d_z <= z1 - t;
143 if (p.
d_y < y1 - t - eps || p.
d_y > y1 + eps)
145 const bool oxz = p.
d_x >= x0 && p.
d_x <= x1 && p.
d_z >= z0 && p.
d_z <= z1;
147 p.
d_x >= x0 + t && p.
d_x <= x1 - t && p.
d_z >= z0 + t && p.
d_z <= z1 - t;
151 if (p.
d_y < y0 - eps || p.
d_y > y0 + t + eps)
153 const bool oxz = p.
d_x >= x0 && p.
d_x <= x1 && p.
d_z >= z0 && p.
d_z <= z1;
155 p.
d_x >= x0 + t && p.
d_x <= x1 - t && p.
d_z >= z0 + t && p.
d_z <= z1 - t;
159 if (p.
d_z < z1 - t - eps || p.
d_z > z1 + eps)
161 const bool oxy = p.
d_x >= x0 && p.
d_x <= x1 && p.
d_y >= y0 && p.
d_y <= y1;
163 p.
d_x >= x0 + t && p.
d_x <= x1 - t && p.
d_y >= y0 + t && p.
d_y <= y1 - t;
167 if (p.
d_z < z0 - eps || p.
d_z > z0 + t + eps)
169 const bool oxy = p.
d_x >= x0 && p.
d_x <= x1 && p.
d_y >= y0 && p.
d_y <= y1;
171 p.
d_x >= x0 + t && p.
d_x <= x1 - t && p.
d_y >= y0 + t && p.
d_y <= y1 - t;
183 const double t =
d_t;
184 const double Vout = Lx * Ly * Lz;
185 const double Vin = std::max(0., (Lx - 2. * t) * (Ly - 2. * t) * (Lz - 2. * t));
186 const double Vclosed = Vout - Vin;
191 if (Vclosed <= 1.0e-30)
194 if (d_openFace < 0 || d_openFace > 5)
200 Aface = Ly * Lz - std::max(0., (Ly - 2. * t) * (Lz - 2. * t));
205 Aface = Lx * Lz - std::max(0., (Lx - 2. * t) * (Lz - 2. * t));
210 Aface = Lx * Ly - std::max(0., (Lx - 2. * t) * (Ly - 2. * t));
215 const double Vroof = Aface * t;
216 const double Vopen = Vclosed - Vroof;
217 if (Vopen <= 1.0e-30)
219 return (1. / Vopen) * (Vclosed * c_closed - Vroof * c_roof);
229 for (
int i = 0; i < 8; ++i)
230 c[i] =
mapSimilarity(c[i], c0, translation, scale, angle, axis, rotationPoint);
240 const double t =
d_t;
241 const double Vout = Lx * Ly * Lz;
242 const double Vin = std::max(0., (Lx - 2. * t) * (Ly - 2. * t) * (Lz - 2. * t));
243 const double Vclosed = Vout - Vin;
246 Aface = Ly * Lz - std::max(0., (Ly - 2. * t) * (Lz - 2. * t));
248 Aface = Lx * Lz - std::max(0., (Lx - 2. * t) * (Lz - 2. * t));
250 Aface = Lx * Ly - std::max(0., (Lx - 2. * t) * (Ly - 2. * t));
251 const double Vroof = Aface * t;
252 return std::max(0., Vclosed - Vroof);
270 for (
int i = 0; i < 8; ++i)
271 r = std::max(r, (c8[i] - c).length());
286 const bool &within)
const {
287 if (!
isNear(x, within ? 0. : tol))
309 bool intersect =
false;
317 const double &tol)
const {
330 std::ostringstream oss;
331 oss << tabS <<
"------- OpenCuboidChannel3D (open shell) --------" << std::endl;
335 oss << tabS <<
"Center (d_x) = " <<
d_x.
printStr() << std::endl;
337 oss << tabS <<
"volume = " <<
volume() << std::endl;
Defines abstract geometrical domain.
std::vector< std::string > d_tags
Tags/attributes about the object.
Hollow axis-aligned cuboid shell with uniform wall thickness and one outer face open.
int d_openFace
Which outer face is open: 0=+x, 1=−x, 2=+y, 3=−y, 4=+z, 5=−z (world axes after transform).
bool inClosedShell(const util::Point &p) const
bool inRemovedFaceSlab(const util::Point &p) const
util::Point d_x
Centroid of the open shell (cached).
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
util::Point d_lo
Outer AABB low corner.
util::Point center() const override
Computes the center of object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
Checks if point is within given distance of this object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
util::Point computeCenter() const
OpenCuboidChannel3D & operator=(const OpenCuboidChannel3D &other)
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
double d_t
Wall thickness.
void validateAndRefreshCenter()
std::string printStr(int nt=0, int lvl=0) const override
Returns the string containing printable information about the object.
util::Point d_hi
Outer AABB high corner.
void validateParams(double x0, double y0, double z0, double x1, double y1, double z1, double t, int open_face)
void aabbFromCorners(const util::Point *c, util::Point &lo, util::Point &hi)
void cornersFromAabb(const util::Point &lo, const util::Point &hi, util::Point *out8)
util::Point mapSimilarity(const util::Point &x, const util::Point &pivotDefault, const util::Point &t, double scale, double angle, const util::Point &axis, const util::Point *rotationPoint)
bool isPointInsideBox(util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
Returns true if point is inside box.
bool areBoxesNear(const std::pair< util::Point, util::Point > &b1, const std::pair< util::Point, util::Point > &b2, const double &tol, size_t dim)
Checks if given two boxes are within given distance from each other.
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
std::string getTabS(int nt)
Returns tab spaces of a given size.
A structure to represent 3d vectors.
double d_y
the y coordinate
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
double d_z
the z coordinate
double d_x
the x coordinate