0

Original(2018.11.01)

I have 3 numpy:x、y、z,created by my laser scanner(40 degree / 1 step). I want to used them to build a 3D model.

I think it must should be use matplotlib.tri
But I have no idea to decide triangulated data

Here is my data :https://www.dropbox.com/s/d9p62kv9jcq9bwh/xyz.zip?dl=0

And Original model:https://i.stack.imgur.com/APdO2.jpg

Code:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.tri as mtri    

x_all=np.load("x.npy")
y_all=np.load("y.npy")
z_all=np.load("z.npy")

tri = #I have no idea...

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x_all,y_all,z_all,triangles=tri.triangles)

Thank so much.

Update(2018.11.02)

I try this way to decide triangulated data Delaunay Triangulation of points from 2D surface in 3D with python?

code:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.tri as mtri
from stl import mesh

x_all=np.load("x.npy")
y_all=np.load("y.npy")
z_all=np.load("z.npy")

model=np.vstack((x_all,y_all,z_all))
model=np.transpose(model)
model -= model.mean(axis=0)
rad = np.linalg.norm(model, axis=1)
zen = np.arccos(model[:,-1] / rad)
azi = np.arctan2(model[:,1], model[:,0])

tris = mtri.Triangulation(zen, azi)

plt.show()

And my model looks like:

https://i.stack.imgur.com/KVPHP.png

https://i.stack.imgur.com/LLQsQ.png

https://i.stack.imgur.com/HdzFm.png

Even though it has better surface on it,but there is a big hole over my model.Any idea to fixs it?

  • Possibly start with [`zip`](https://docs.python.org/3/library/functions.html#zip) or [`dstack`](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.dstack.html#numpy-dstack) to get the coords into a single array? – 0x5453 Nov 01 '18 at 13:12

1 Answers1

1

Assuming you want to reduce the complexity, i.e find triangles in your files to reduce the complexity. You may look into fitting a convex hull to your points, see here fore more info

Based on the file you provided this produces a surf plot of the object.

from numpy import load, stack
from matplotlib.pyplot import subplots
from mpl_toolkits.mplot3d import Axes3D
from scipy import spatial


x = load("x.npy")
y = load("y.npy")
z = load("z.npy")
points = stack((x,y,z), axis = -1)

v = spatial.ConvexHull(points)
fig, ax = subplots(subplot_kw = dict(projection = '3d'))
ax.plot_trisurf(*v.points.T, triangles = v.simplices.T)
fig.show()

output

cvanelteren
  • 1,633
  • 9
  • 16
  • Thank you for your answer , But your model has to many hole. My purpose is that without any hole so that could transfer a stl file for 3D printer. – LiangJinWei Nov 01 '18 at 15:16
  • What do you mean exactly with holes? Is the object supposed to not be hollow? It seems like a cap based on the raw data. If the data shouldn't be hollow you can triangulate the x,y plane for every z. – cvanelteren Nov 02 '18 at 08:30
  • Actually , my original model is a cylinder ( https://i.imgur.com/XSyONff.jpg ) .My purpose that its surface could like it. – LiangJinWei Nov 02 '18 at 09:25