Skip to content

Instantly share code, notes, and snippets.

@nicoguaro
Created March 15, 2023 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicoguaro/dbb2ef7d9e724406a1c97fcbbd1bf03c to your computer and use it in GitHub Desktop.
Save nicoguaro/dbb2ef7d9e724406a1c97fcbbd1bf03c to your computer and use it in GitHub Desktop.
Heart surface
import numpy as np
import matplotlib.pyplot as plt
from skimage import measure
y, x, z = np.mgrid[-2:2:100j, -2:2:100j, -2:2:100j]
f = (x**2 + 9/4*y**2 + z**2 - 1)**3 - x**2 * z**3 - 9/80*y**2*z**3
verts, faces, _, _ = measure.marching_cubes(f, 0, spacing=(0.1, 0.1, 0.1))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(verts[:, 0], verts[:,1], faces, verts[:, 2],
cmap='Spectral', lw=1)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment