Repository navigation
Replies: 4 comments 4 replies
|
I'm having trouble visualizing what you're doing - do you have an image? I agree that it seems like this is a pretty simple op that doesn't require 3D. |
|
If I'm reading it right: a square with a square hole, sliced at a y that passes through the hole, gives two intervals - If that's the operation, it looks like a fairly small thing to add - a scanline over the edges, with the same boundary conventions |
|
Thinking about it more - a 2D |
|
Correction to my last comment - this is doable today with no new API: // The intervals of the horizontal line y that lie inside `cs`.
std::vector<vec2> SliceAt(const CrossSection& cs, double y) {
const Rect b = cs.Bounds();
const CrossSection above(Rect({b.min.x - 1, y}, {b.max.x + 1, b.max.y + 1}));
std::vector<vec2> out;
for (const auto& ring : (cs ^ above).ToPolygons()) {
const size_t n = ring.size();
for (size_t i = 0; i < n; ++i) {
const vec2 p = ring[i], q = ring[(i + 1) % n];
if (p.y == y && q.y == y)
out.push_back({std::min(p.x, q.x), std::max(p.x, q.x)});
}
}
return out; // pieces may abut; sort and merge if you care
}Clip to the half-plane above the line, then read the boundary edges lying on it. The rectangle's extent doesn't matter and there is no epsilon to pick. On a square with a hole that closes at y=1.1 this gives So |





Uh oh!
There was an error while loading. Please reload this page.
The project I'm working on would benefit from a shorter version of these steps:
CrossSectionin some wayManifold::ExtrudetheCrossSectionManifoldso that thexandzoryandzaxes are swappedManifold::Sliceso we now have a 1D slice of the originalCrossSectionextruded to a set of rectanglesCrossSectionfrom the result ofSliceI'm pretty sure there should be a way to do this without passing through 3-space.
I don't know how common the operation of slicing a polygon into a set of line segments and then extruding it back into a polygon is, but hopefully it's common enough to be worth however much code this takes.
All reactions