xmesh: A 1k lines N-D Delaunay triangulation

xmesh-python: A 20 lines xtensor-numpy bindings for xmesh


In [1]:
import numpy as np
import pymesh
import bqplot.pyplot as plt

2-D Mesh computed with xtensor, plotted with bqplot


In [2]:
points = np.random.randn(100, 2)
mesh = pymesh.Mesh(points)

In [3]:
lines = np.stack(simplex.lines() for simplex in mesh)
plt.figure()

plt.plot(lines[:,:,0], 
         lines[:,:,1],
         close_path=True,
         colors=['red'],
         stroke_width=1)

plt.scatter(x=points[:,0],
            y=points[:,1])

plt.show()


A simple application with ipywidgets and bqplot


In [4]:
lines = np.stack(simplex.lines() for simplex in mesh)

def update_lines(change):
    with simplices.hold_sync():
        points = np.stack([scatter.x, scatter.y], axis=1)
        mesh = pymesh.Mesh(points)
        lines = np.stack(simplex.lines() for simplex in mesh)
        simplices.x = lines[:,:,0]
        simplices.y = lines[:,:,1]

plt.figure()
simplices = plt.plot(lines[:,:,0], lines[:,:,1], close_path=True, colors=['red'], stroke_width=1)
scatter = plt.scatter(x=points[:,0], y=points[:,1], enable_move=True)
plt.show()

scatter.observe(update_lines, names=['x', 'y'])



In [ ]: