Hi Matt, thanks for the help. With your hint I could refactor a lot of the old
code. There are two questions left: I used the PolyhedronSet to determine the intersections with a line. First I got a Plane and then I had to find the intersection with the Plane. My code makes use of both, the Plane and the intersection. 1. Can I use RegionBSPTree3D.linecast for the intersection part ? 2. Is there a way to find out the intersected Plane ? Regards, Sven On 6/11/20 3:57 AM, Matt Juntunen wrote:
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 <sven.rathge...@web.de> Sent: Wednesday, June 10, 2020 3:28 AM To: Commons Developers List <dev@commons.apache.org> 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: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org
--------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org