GouMinghao / Geometry3D

Geometry3D: 3D Computational Geometrics Library
GNU General Public License v3.0
88 stars 23 forks source link

Bug in ConvexPolygon-Plane intersection #11

Closed ThomasCassimon closed 2 years ago

ThomasCassimon commented 2 years ago

There is currently a bug in the code for ConvexPolygon-Plane Intersection. This bug is caused by a minor typo, and can be fixed relatively easily.

If you look at line 98-101 in "Geometry3D/calc/intersection.py", you'll find this code:

    elif isinstance(a, Plane) and isinstance(b, ConvexPolygon):
        return inter_plane_convexpolygon(a,b)
    elif isinstance(a, ConvexPolygon) and isinstance(a, Plane):
        return inter_plane_convexpolygon(b,a)

In the second elif statement, you can see that we are checking the type of a twice, without checking the type of b.

This should be changed to the following:

    elif isinstance(a, Plane) and isinstance(b, ConvexPolygon):
        return inter_plane_convexpolygon(a,b)
    elif isinstance(a, ConvexPolygon) and isinstance(b, Plane):
        return inter_plane_convexpolygon(b,a)

Until then, the work-around is to simply always specify the Plane first, and the ConvexPolygon second, so that you trigger the first elif, rather than the second.

Thanks in advance!

GouMinghao commented 2 years ago

Thank you for your great bug report which is difficult for me to find. Your suggestion will be merged in the soon fix.