line2mesh_quads.py 680 B

1234567891011121314151617181920212223242526272829
  1. """Mesh a line contour with quads of variable resolution"""
  2. from vedo import Spline, Grid, show
  3. import numpy as np
  4. pts = [
  5. [0.0, 0.0],
  6. [1.0, 0.0],
  7. [1.1, 4.0],
  8. [1.0, 1.5],
  9. [0.2, 5.0],
  10. [-1., 3.0],
  11. [0.4, 2.7],
  12. [-1., 2.4],
  13. ]
  14. shape = Spline(pts, closed=True).color('red4').linewidth(5)
  15. xcoords = np.arange(-2.0, 2.5, 0.075)
  16. ycoords = np.arange(-0.5, 5.5, 0.075)
  17. xcoords += np.cos(xcoords+0.6)*0.75 # make quads shrink and stretch
  18. ycoords += np.sin(ycoords+0.5)*0.75 # to refine mesh resolution
  19. grd = Grid(s=[xcoords, ycoords]) # create a gridded plane
  20. msh = shape.generate_mesh(grid=grd, quads=True)
  21. show(shape, msh, __doc__, axes=1).close()