Goal: I am trying to calculate the volume of two intersecting convex hulls. One hull is from a large point cloud of varying sizes, the other is a cuboid (block) that is [1m x 1m x 0.5m].
Problem: I am able to use the centroid of the block as the interior_point, but this fails when the intersection is less then half of the block. So I need to properly compute the interior-point using scipy.optimize.linprog
. I found a similar problem here, but have not being succesfull in any implementations.
Question: How do I use scipy.optimize.linprog
to find the interior_point of my intersecting convex hulls?
# 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)
Here is an example of a functional block (Volume 0.26, Percent 51.67%)
Exception Thrown
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