"""Voronoi tessellation of a pointcloud on a grid""" from vedo import dataurl, Points, Grid, voronoi, show pts0 = Points(dataurl + 'rios.xyz').color('k') pts1 = pts0.clone().smoothLloyd2D() grid = Grid([14500, 61700], sx=22000, sy=24000, resx=30, resy=30).ps(1) allpts = pts1.points().tolist() + grid.points().tolist() msh = voronoi(allpts, method='scipy') msh.lw(0.1).wireframe(False).cmap('terrain_r', 'VoronoiID', on='cells') centers = Points(msh.cellCenters(), c='k') show(msh, pts0, __doc__, axes=dict(digits=3))
v += 0.05*np.random.uniform(-1, 1, (n, n)) sy, sx = V.shape grd = Grid(sx=sx, sy=sy, resx=sx, resy=sy) grd.lineWidth(0).wireframe(False).lighting(ambient=0.5) formula = r'(u,v)=(D_u\cdot\Delta u -u v v+F(1-u), D_v\cdot\Delta v +u v v -(F+k)v)' ltx = Latex(formula, s=15, pos=(0,-sy/1.9,0)) print('Du, Dv, F, k, name =', Du, Dv, F, k, name) settings.useDepthPeeling = False for step in range(Nsteps): for i in range(25): Lu = ( U[0:-2, 1:-1] + U[1:-1, 0:-2] - 4*U[1:-1, 1:-1] + U[1:-1, 2:] + U[2: , 1:-1]) Lv = ( V[0:-2, 1:-1] + V[1:-1, 0:-2] - 4*V[1:-1, 1:-1] + V[1:-1, 2:] + V[2: , 1:-1]) uvv = u*v*v u += Du*Lu - uvv + F*(1-u) v += Dv*Lv + uvv - (F+k)*v grd.cmap('ocean_r', V.ravel(), on='cells', arrayName="escals") grd.mapCellsToPoints() newpts = grd.points() newpts[:,2] = grd.getPointArray('escals')*25 # assign z grd.points(newpts) # set the new points plt = show(ltx, grd, zoom=1.25, elevation=-.15, bg='linen', interactive=False) if plt.escaped: break # if ESC is hit during loop interactive().close()
"""The butterfly effect with cylindrical mirrors and a laser""" # Original idea from "The Action Lab": https://www.youtube.com/watch?v=kBow0kTVn3s # from vedo import Plotter, Grid, Cylinder, merge from optics_base import Ray, Mirror, Detector # see file ./optics_base.py grid = Grid(resx=3, resy=4) # pick a few points in space to place cylinders pts = grid.points().tolist() + grid.cellCenters().tolist() # Create the mirror by merging many (y-scaled) cylinders into a single mesh object cyls = [ Cylinder(p, r=0.065, height=0.2, res=720).scale([1, 1.5, 1]) for p in pts ] mirror = Mirror(merge(cyls)).color("silver") # Create a detector surface as a thin cylinder surrounding the mirror sd = Cylinder(r=1, height=0.3, cap=False).cutWithPlane([0, -0.95, 0], normal='y') detector = Detector(sd) def slider(widget, event): ### callback to shift the beam along x dx = widget.GetRepresentation().GetValue() ray = Ray([dx, -1.2, -0.1], direction=(0, 1, 0.02)) ray.maxiterations = 1000 # max nr. of reflections ray.trace([mirror, detector]) # cumpute trajectory detector.count().cmap("Reds", on='cells', vmax=10) line = ray.asLine().lineWidth(4).c('green5') if plt.actors[-1].name == "Line": plt.pop() # remove the last Line plt.add(line) # add the new one