Skip to content

Latest commit

 

History

History
42 lines (36 loc) · 1.15 KB

README.md

File metadata and controls

42 lines (36 loc) · 1.15 KB

np2stl

Create 3D STL files from numpy data

Installation:

  1. Clone the repository
git clone git@github.com:lhalve/np2stl.git
  1. Install dependencies
cd np2stl
pip3 install -r requirements.txt
  1. Add this repository to your PYTHONPATH environment variable
cd np2stl
export PYTHONPATH="${PYTHONPATH}:$PWD"

Usage:

Example usage for a numpy 2-dimensional histogram:

import numpy as np
from np2stl import stl_builder

# create random numbers according to a 2d Gaussian distribution
rand = np.random.multivariate_normal([4, 7], np.diag([2, 3]), size=1000000)
# create a 2-dimensional histogram of these data
hist = np.histogram2d(rand[:, 0], rand[:, 1], bins=100)

# intialize the 3d object
builder = stl_builder.STLBuilder()
# feed the histogram to the 3d object
builder.from_numpy_2dhist(*hist)
# save the 3d object to a stl
builder.save("gauss_2d.stl")

Output:

You can view .stl files with any 3d viewer. The example above creates an stl file similar to this: Screenshot of a view of a .stl file of a two-dimension Gaussian distribution.