Hi Sven,
No problem! To answer your question in the subject line, yes, RegionBSPTree3D
is the replacement for the old PolyhedronsSet. They both represent 3D regions
using BSP trees. As for your code example, you're probably going to want to use
Planes.indexedConvexPolygons() [1] or Planes.indexedTriangles() [2] to create a
list of ConvexPolygon3D instances and then use those to create a
RegionBSPTree3D:
public static PolyhedronsSet createPrism(
List<Position2D> basePolygon,
int upperBound,
int lowerBound) {
List<Vector3D> vertices = createVertices(polygon, upperBound, lowerBound);
int[][] facets = createFacets(polygon);
List<ConvexPolygon3D> polys = Planes.indexedConvexPolygons(vertices,
facets, PRECISION_CONTEXT);
return RegionBSPTree3D.from(polys);
}
There is actually a unit test here [3] that does exactly this.
Note that if the region is convex and you have a large number of polygons to
insert, the resulting tree will be highly unbalanced and will suffer from poor
performance. To help with this, you can insert partitions into the BSP tree
that do not affect the represented region but help keep the tree balanced and
shallow. Here's an example:
public static PolyhedronsSet createPrism(
List<Position2D> basePolygon,
int upperBound,
int lowerBound) {
List<Vector3D> vertices = createVertices(polygon, upperBound, lowerBound);
int[][] facets = createFacets(polygon);
// compute the region bounds and centroid
Bounds3D bounds = Bounds3D.from(vertices);
Vector3D centroid = bounds.getCentroid();
// create an empty region
RegionBSPTree3D tree = RegionBSPTree3D.empty();
// insert structural partitions into the tree (RegionCutRule.INHERIT) at
the centroid; the
// resulting tree has internal partitions but the represented region is
still empty
tree.insert(Planes.fromPointAndNormal(center, Vector3D.Unit.PLUS_X,
PRECISION_CONTEXT).span(), RegionCutRule.INHERIT);
tree.insert(Planes.fromPointAndNormal(center, Vector3D.Unit.PLUS_Y,
PRECISION_CONTEXT).span(), RegionCutRule.INHERIT);
tree.insert(Planes.fromPointAndNormal(center, Vector3D.Unit.PLUS_Z,
PRECISION_CONTEXT).span(), RegionCutRule.INHERIT);
// create and insert the region boundaries
List<ConvexPolygon3D> polys = Planes.indexedConvexPolygons(vertices,
facets, PRECISION_CONTEXT);
tree.insert(polys);
return tree;
}
I've created a RegionBSPTree.subdivided() factory method in my current working
branch that abstracts this internal partitioning so this should be less verbose
in the near future.
Let me know if you have any other questions or run into issues. I'm working now
on a tutorial focusing on the BSP tree usage (GEOMETRY-95) so if you find
anything that's confusing or messed up, I can try to address it.
Regards,
Matt
[1]
https://github.com/apache/commons-geometry/blob/master/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Planes.java#L295
[2]
https://github.com/apache/commons-geometry/blob/master/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Planes.java#L234
[3]
https://github.com/apache/commons-geometry/blob/master/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PlanesTest.java#L448
________________________________
From: Sven Rathgeber <[email protected]>
Sent: Wednesday, June 10, 2020 3:28 AM
To: Commons Developers List <[email protected]>
Subject: [geometry] Transition from PolyhedronSet to ??? (RegionBSPTree3D ?)
Hi Matt,
first of all:
Thanks a lot for all your work (rewrite) on the library !!!!
Could you give me a hint how to make the transition from PolyhedronSet
to the new data structures ?
This is my current code:
public static PolyhedronsSet createPrism(
List< Position2D > basePolygon,
int upperBound,
int lowerBound )
{
List< Vector3D > vertices = createVertices( polygon, upperBound,
lowerBound );
int[][] facets = createFacets( polygon );
return new PolyhedronsSet( vertices, Arrays.asList( facets ),
PRECISION_CONTEXT );
}
Cheers. Sven
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]