Giter Club home page Giter Club logo

surf2stl-python's Introduction

Surf2stl.py

Export a surface to a STL(Stereolithography) file.

Description

Functions in this script (write, tri_write) can export 3d surface to a STL (Stereolithography) format file. This is the python version of surf2stl.m in MATLAB (or Octave).

Exported files can be imported in various 3d software tools (like Blender, Meshlab, etc.)

Installation

clone this repository

git clone https://github.com/asahidari/surf2stl-python

Usage

Write python script like this:

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)

Or like this:

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)

If you use jupyter notebook, 'Surf2stl-python_example.ipynb' shows the examples with 3d graphs in matplotlib.

jupyter_notebook_image1 meshlab_image1 jupyter_notebook_image2 meshlab_image2

Requirement

  • Python 3
  • numpy
  • scipy
  • matplotlib (to draw graph in python)

Author

asahidari

License

MIT

surf2stl-python's People

Contributors

asahidari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.