2

目标:我正在尝试计算两个相交凸包的体积。一个船体来自不同大小的大点云,另一个是长方体(块),即 [1m x 1m x 0.5m]。

问题:我可以使用块的质心作为内部点,但是当交叉点小于块的一半时,这会失败。所以我需要使用正确计算内点scipy.optimize.linprog我在这里发现了一个类似的问题,但在任何实现中都没有成功。

问题:如何使用scipy.optimize.linprog找到相交凸包的内部点?

        # Cavity convex hull and halfspace
        shellHull = ConvexHull(shell.values)
        shellHyper = shellHull.equations
        shellHS = np.array(shellHyper).astype(np.double)

        # loop through all blocks
        for j in Centroid.iterrows():
            # print(j)
            x1 = j[1]['x']
            y1 = j[1]['y']
            z1 = j[1]['z']

            # block convex hull and halfspace
            block = util.cuboid_points([x1, y1, z1]) # returns the eight points that form a cuboid
            blockHull = ConvexHull(block)
            blockHyper = blockHull.equations
            blockHS = np.array(blockHyper).astype(np.double)

            halfspaces = np.concatenate((shellHS, blockHS)) # Combine Halfspaces

            percent = 100
            volume = 0.5
            interiorPoint = np.array(
                [x1, y1, z1]).astype(np.double)

            hs = HalfspaceIntersection(
                    halfspaces, interiorPoint)

            volume = ConvexHull(hs.intersections).volume
            percent = volume / 0.5


            cavityPercent = cavityPercent.append({'x': x1, 'y': y1, 'z': z1, 'percentage': percent * 100, 'volume': volume},
                                                 ignore_index=True)

这是一个功能的示例(体积 0.26,百分比 51.67%)

抛出异常

Traceback (most recent call last):
File "~/bChab/Block/Percent_Consumed_v2.py", line 155, in <module>
    hs = HalfspaceIntersection(
File "qhull.pyx", line 2810, in scipy.spatial.qhull.HalfspaceIntersection.__init__
File "qhull.pyx", line 356, in scipy.spatial.qhull._Qhull.__init__
scipy.spatial.qhull.QhullError: QH6023 qhull input error: feasible point is not clearly inside halfspace
feasible point: 10772.5 10072.5 1067.75
    halfspace:     -0     -0      1
    at offset: -1067.75  and distance:      0
The halfspace was at index 368

While executing:  | qhull H
Options selected for Qhull 2019.1.r 2019/06/21:
run-id 1331304314  Halfspace  _maxoutside  0
4

0 回答 0