6

This is a followup of a question of mine at stackoverflow partially reproduced here for clarity.

I'm playing a bit with scikit-image marching cubes algorithm. Here is a simplified version of the example given in the docs.

from matplotlib import pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
from skimage import measure


x = np.linspace(-1, 1, 11)

X, Y, Z = np.meshgrid(x, x, x, indexing = 'ij')

def f(x, y, z):
    return x

verts, faces = measure.marching_cubes(f(X, Y, Z), 0.6)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

mesh = Poly3DCollection(verts[faces])
ax.add_collection3d(mesh)

ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.set_zlim(0, 10)

plt.show()

Here is the resulting surface:

enter image description here

Now I'd like to draw the surface with asymptote. So basically, I have to find a way to export the coordinates of the triangles. Easy: each triangle is an element of verts[faces] represented by 3 lists, the elements being the 3 coordinates of each vertice. So I can parse verts[faces] and write to a file path3 triangle = (x1, y1, z1) -- (x2, y2, z2) -- (x3, y3, z3) -- cycle for each triangle. Then, for each triangle, I draw the surface: draw(surface(triangle)). But is there a better way to define the surface for asymptote?

Note that in real life, the surface is far more complex than a simple plane :)

cjorssen
  • 10,032
  • 4
  • 36
  • 126
  • I know that my question is very near off topic. But it is directly related to asymptote and people are nice here! – cjorssen May 25 '16 at 13:11
  • I'm unsure whether this very well phrased question question is on topic... I better upvote it ;) – Henri Menke May 25 '16 at 13:54
  • Just a thought - Asymptote has an obj module to construct surfaces from .obj files. You can export your triangles to the .obj format, the spec is available online, and plot the surface this way. – MindV0rtex May 25 '16 at 16:20
  • See http://tex.stackexchange.com/a/282390/484, specifically surface toreturn and the three lines beginning patch triangle =. (Only ignore the line about normals, that has been removed since I wrote that answer.) – Charles Staats May 25 '16 at 23:31
  • @CharlesStaats I have a solution based on your comment. Do you want to answer or should I answer myself? – cjorssen May 26 '16 at 11:29
  • Please answer yourself. – Charles Staats May 26 '16 at 23:10

0 Answers0