I would like to mesh the surface of a cloud of points that may not be completely convex, for example the points in this question. Mathematica does not provide triangulation of 3D points, but there is a link to TetGen
Needs["TetGenLink`"]
{mypts, mysurface} = TetGenConvexHull[dat];
Graphics3D[GraphicsComplex[mypts, Polygon[mysurface]], Boxed -> False]
which results in this
Notice it doesn't get the surface meshing associated with subtle twist in the curved shape, and meshes points further away in the goal of creating a convex object. I suppose one could try to mesh the surface piece by piece and slowly merge it as in this answer, but that sounds like a nightmare.
Here is the cloud of points for reference:
Answer
Using Simon's answer (all credit to him):
Needs["TetGenLink`"]
file = "https://dl.dropboxusercontent.com/u/68983831/curved_pipe02.txt";
dat = Import[file, "Table"];
{pts, tetrahedra} = TetGenDelaunay[dat];
csr[{aa_, bb_, cc_, dd_}] :=
With[{a = aa - dd, b = bb - dd, c = cc - dd},
Norm[a.a Cross[b, c] + b.b Cross[c, a] +
c.c Cross[a, b]]/(2 Norm[a.Cross[b, c]])]
radii = csr[pts[[#]]] & /@ tetrahedra;
alphashape[rmax_] := Pick[tetrahedra, radii, r_ /; r < rmax]
faces[tetras_] :=
Flatten[tetras /. {a_, b_, c_,
d_} :> {{a, b, c}, {a, b, d}, {a, c, d}, {b, c, d}}, 1]
externalfaces[faces_] :=
Cases[Tally[Sort /@ faces], {face_, 1} :> face]
polys = externalfaces@faces@alphashape[.001];
Graphics3D[GraphicsComplex[pts, Polygon@polys], Boxed -> False]
polys = externalfaces@faces@alphashape[.001];
Graphics3D[GraphicsComplex[pts, Polygon@polys], Boxed -> False]
Comments
Post a Comment