# How to cut a convexhull by a surface

Hello everyone, I have built a convexhull from a list of points using the ConvexHully function of scipy.spatial

``````H=ConvexHull(points)
PH=H.points
vh=H.vertices
sh=H.simplices
go.Mesh3d(x=PH[:, 0],y=PH[:, 1], z=PH[:, 2],
name='Hull',
showlegend=True,
color='gray',
i=sh[:, 0], j=sh[:, 1], k=sh[:, 2],
opacity=1,
alphahull=1,
showscale=False)

``````

and on the other hand I have drawn a surface from a grid, using go.Surface.

``````   tx=grid[0]
ty=grid[1]
tz=grid[2]

X = np.linspace(min(tx), max(tx))
Y = np.linspace(min(ty), max(ty))
X, Y = np.meshgrid(X, Y)
Z = griddata((tx,ty),tz,(X,Y), method='linear)
go.Surface( x=X,y=Y,z=Z,
colorscale=blues,
opacity = 1,
name='Topography',
showlegend=True,
showscale=False)

``````

I would like to erase the part of the convexhull that is above the surface.

Any suggestions?
Thanks

If you have control at the vertex level on X,Y,Z (which seems to be from the code), just clamp the proper axis with either a math library function or hand-roll your own.

Fancier things would require collision checking/vector math/minkowski difference kind of solutions.