polytex.thirdparty.surf2stl package
Submodules
polytex.thirdparty.surf2stl.surf2stl module
- polytex.thirdparty.surf2stl.surf2stl.tri_write(filename, x, y, z, tri, mode='binary')[source]
Write a stl file for a surface with geometry defined from three matrix arguments, x, y, and z with Delaunay Triangle parameter(tri).
Meshes are triangulated with the ‘tri’ parameter usually made with parameters which determine the sequence of vertices (like [u, v]).
- Parameters
- filenamestring
output file name
- x, y, zndarray
Each of these arguments must be 1-dimensional.
- triscipy.spatial.Delaunay
Delaunay Triangulation object. When xyz coordinates are determined from other parameters(like (u, v)), this triangle faces are basically calculated with the parameters.
- modestring
STL file format, ‘ascii’ or ‘binary’(default).
Examples
import numpy as np from scipy.spatial import Delaunay import surf2stl
u = np.linspace(0, 2.0 * np.pi, endpoint=True, num=50) v = np.linspace(-0.5, 0.5, endpoint=True, num=10) u, v = np.meshgrid(u, v) u, v = u.flatten(), v.flatten()
x = (1 + 0.5 * v * np.cos(u / 2.0)) * np.cos(u) y = (1 + 0.5 * v * np.cos(u / 2.0)) * np.sin(u) z = 0.5 * v * np.sin(u / 2.0)
delaunay_tri = Delaunay(np.array([u, v]).T) surf2stl.tri_write(‘mobius.stl’, x, y, z, delaunay_tri)
- polytex.thirdparty.surf2stl.surf2stl.write(filename, x, y, z, mode='binary')[source]
Write a stl file for a surface with geometry defined from three matrix arguments, x, y, and z. Meshes are triangulated sequencially along xyz order.
- Parameters
- filenamestring
output file name
- x, y, zndarray
Arguments x, y can be 1-dimensional arrays or 2-dimensional grids (usually generated by np.meshgrid(x,y)), and z must be 2-dimensional, which must have len(x)=n, len(y)=m where z.shape[m,n].
- modestring
STL file format, ‘ascii’ or ‘binary’(default).
Examples
import numpy as np import surf2stl
x = np.linspace(-6, 6, 30) y = np.linspace(-6, 6, 30) X, Y = np.meshgrid(x, y) Z = np.sin(np.sqrt(X ** 2 + Y ** 2))
surf2stl.write(‘3d-sinusoidal.stl’, X, Y, Z)