silhouette2.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """Generate the silhouette of a mesh
  2. as seen along a specified direction
  3. Axes font: """
  4. # Author: Zhi-Qiang Zhou (https://github.com/zhouzq-thu)
  5. from vedo import *
  6. settings.default_font = "Kanopus"
  7. s = Hyperboloid().rotate_x(20)
  8. pts = s.points
  9. n = len(pts)
  10. plt = Plotter(title="Example of project_on_plane()")
  11. plt += [s, __doc__ + settings.default_font]
  12. # orthogonal projection ###############################
  13. plane1 = Plane(pos=(2, 0, 2), normal=(1, 0, 1), s=[5, 5]).alpha(0.1)
  14. so = s.clone().project_on_plane(plane1).c("y")
  15. plt += [plane1, so, so.silhouette("2d")]
  16. pts1 = so.silhouette("2d").points
  17. # perspective projection ##############################
  18. plane2 = Plane(pos=(3, 3, 3), normal=(1, 1, 1), s=[5, 5]).alpha(0.1)
  19. point = [6, 6, 6]
  20. sp = s.clone().project_on_plane(plane2, point=point).c("m")
  21. plt += [plane2, sp, sp.silhouette("2d")]
  22. # oblique projection ##################################
  23. plane3 = Plane(pos=(4, 8, -4), normal=(-1, 0, 1), s=[5, 5]).alpha(0.1)
  24. sob = s.clone().project_on_plane(plane3, direction=(1, 2, -1)).c("g")
  25. plt += [plane3, sob, sob.silhouette("2d")]
  26. pts2 = sob.silhouette("2d").points
  27. # draw the lines
  28. for i in range(0, n, int(n / 20)):
  29. plt += Line(pts1[i], pts[i]).color("black",0.2)
  30. plt += Line(point, pts[i]).color("black",0.2)
  31. plt += Line(pts2[i], pts[i]).color("black",0.2)
  32. plt.show(
  33. axes=dict(
  34. xtitle="X-axis in :mum",
  35. ytitle="Y-axis in :mum",
  36. ztitle="Z-axis in :mum",
  37. yzgrid=False,
  38. text_scale=1.5,
  39. ),
  40. ).close()