This may be related to the fact that you are using the 3D API with 2D
areas. Since the shapes have no volume the intersection may not be defined.

This does work as expected in 2D:

        Precision.DoubleEquivalence precision =
Precision.doubleEquivalenceOfEpsilon(1e-6);

        List<Vector2D> pts1 = new ArrayList<>();
        pts1.add(Vector2D.of(0, 10));
        pts1.add(Vector2D.of(30, 10));
        pts1.add(Vector2D.of(30, 20));
        pts1.add(Vector2D.of(0, 20));
        ConvexArea face1 = ConvexArea.convexPolygonFromVertices(pts1,
precision);

        List<Vector2D> pts2 = new ArrayList<>();
        pts2.add(Vector2D.of(10, 0));
        pts2.add(Vector2D.of(20, 0));
        pts2.add(Vector2D.of(20, 30));
        pts2.add(Vector2D.of(10, 30));
        ConvexArea face2 = ConvexArea.convexPolygonFromVertices(pts2,
precision);

        RegionBSPTree2D bsp1 = RegionBSPTree2D.from(face1.getBoundaries());

        RegionBSPTree2D bsp2 = RegionBSPTree2D.from(face2.getBoundaries());

        RegionBSPTree2D result = RegionBSPTree2D.empty();
        result.intersection(bsp1, bsp2);

        System.out.println("Hello, Geometry! Centroid: " +
result.getCentroid());

Result:

        Hello, Geometry! Centroid: (15.000000000000002, 15.000000000000002)

There may be a setting for the 3D equivalent to allow intersections on the
plane to be returned. I could not find anything obvious in the API.

Regards,

Alex



On Fri, 16 Sept 2022 at 10:03, Bai Song <baisongm...@163.com> wrote:

> Hi, Geometry Team
>
> I'm learning this interesting project and facing some difficulties when i
> did a little experiment.
>
> I created two ConvexPolygon3D instances (2 white rectangles in below
> image) on the same plane, and try to get the overlaping area(blue part) by
> RegionBSPTree3D intersection operation.
>
>
> But i got null when getting the centroid of the intersection. It looks
> that this test of intersection failed.
> Could you tell me how can i fix this?
>
> Thanks for your contribution to this project!
>
> //---------my test codes----------
> public class TestIntersection
> {
>     public static void main(String args[])
>     {
>         Precision.DoubleEquivalence precision =
> Precision.doubleEquivalenceOfEpsilon(1e-6);
>
>         List<Vector3D> pts1 = new ArrayList<>();
>         pts1.add(Vector3D.of(0, 10, 0));
>         pts1.add(Vector3D.of(30, 10, 0));
>         pts1.add(Vector3D.of(30, 20, 0));
>         pts1.add(Vector3D.of(0, 20, 0));
>         ConvexPolygon3D face1=Planes.convexPolygonFromVertices(pts1,
> precision);
>
>         List<Vector3D> pts2 = new ArrayList<>();
>         pts2.add(Vector3D.of(10, 0, 0));
>         pts2.add(Vector3D.of(20, 0, 0));
>         pts2.add(Vector3D.of(20, 30, 0));
>         pts2.add(Vector3D.of(10, 30, 0));
>         ConvexPolygon3D face2 = Planes.convexPolygonFromVertices(pts2,
> precision);
>
>         List<ConvexPolygon3D> list1 = new ArrayList<>();
>         list1.add(face1);
>         RegionBSPTree3D bsp1 = RegionBSPTree3D.from(list1);
>
>         List<ConvexPolygon3D> list2 = new ArrayList<>();
>         list2.add(face2);
>         RegionBSPTree3D bsp2 = RegionBSPTree3D.from(list2);
>
>         RegionBSPTree3D result = RegionBSPTree3D.empty();
>         result.intersection(bsp1, bsp2);
>
>         System.out.println("Hello, Geometry! Centroid:
> "+result.getCentroid()); //expect (15,15,0), but got null actually
>     }
> }
>
>

Reply via email to