Hi Sven,
If the createVertices and createFacets methods don't construct convex polygons
then perhaps you could bypass them completely and just construct the tree
directly from the boundaries. Assuming that I understand your use case
correctly, the following methods should do what you want:
private RegionBSPTree3D createPrism(List<Vector2D> polygon,
double upperBound, double lowerBound,
DoublePrecisionContext precision) {
EmbeddingPlane plane = Planes.fromPointAndPlaneVectors(Vector3D.of(0, 0,
lowerBound),
Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y, precision);
Vector3D extrudeVector = plane.getNormal().withNorm(upperBound -
lowerBound);
return extrudePolygon(polygon, plane, extrudeVector, precision);
}
private RegionBSPTree3D extrudePolygon(List<Vector2D> polygon, EmbeddingPlane
plane,
Vector3D extrudeVector, DoublePrecisionContext precision) {
List<Vector3D> basePoints = plane.toSpace(polygon);
List<Vector3D> extrudedPoints = basePoints.stream()
.map(extrudeVector::add)
.collect(Collectors.toList());
RegionBSPTree3D tree = RegionBSPTree3D.empty();
// treat the plane as the top and the extruded plane as the bottom;
// we'll invert the tree at the end if needed
tree.insert(plane.span()); // top
tree.insert(Planes.fromPointAndNormal(
plane.getOrigin().add(extrudeVector),
plane.getNormal().negate(),
precision).span()); // bottom
// create the sides of the prism
int size = polygon.size();
for (int i = 0; i < size; ++i) {
tree.insert(Planes.convexPolygonFromVertices(Arrays.asList(
basePoints.get(i),
extrudedPoints.get(i),
extrudedPoints.get((i + 1) % size),
basePoints.get((i + 1) % size)
), precision));
}
// complement the tree if the "top" wasn't actually the top
if (plane.getNormal().dot(extrudeVector) > 0) {
tree.complement();
}
return tree;
}
Note that these methods assume that the polygon contains at least 3 unique
vertices, the first vertex is not repeated at the end, and that the upper and
lower bounds are not equal.
Hopefully this helps.
Regards,
Matt
________________________________
From: Sven Rathgeber <[email protected]>
Sent: Tuesday, June 16, 2020 3:46 AM
To: Commons Developers List <[email protected]>
Subject: Re: [geometry] Transition from PolyhedronSet to ??? (RegionBSPTree3D ?)
Hi Matt,
> 2. Yes, the LinecastPoint3D object that you get from linecasting
contains the intersection point as well as the surface normal at the
point of intersection.
thanks - that did the job and I could do the whole refactoring, but the
tests fail.
We used the PolyHedronsSet to model non-convex regions and that worked well.
Now the "indexedConvexPolygons" is strict and forbids that (walk your
talk :) ).
Is there a way to handle non-convex regions ?
Regards,
Sven
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]