madcad1.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Example of usage of the madcad library
  2. # See https://pymadcad.readthedocs.io/en/latest/index.html
  3. import vedo
  4. from madcad import *
  5. ##########################################################################
  6. points = [O, X, X + Z, 2 * X + Z, 2 * (X + Z), X + 2 * Z, X + 5 * Z, 5 * Z]
  7. section = Wire(points).segmented().flip()
  8. rev = revolution(2 * pi, (O, Z), section)
  9. rev.mergeclose()
  10. vedo.show("Revolution of a wire", rev, axes=7).close()
  11. ##########################################################################
  12. # m = screw(10, 20)
  13. # m["part"].option(color=vec3(70, 130, 180) / 255) # RGB
  14. # vedo.show("A blue screw", m, axes=1).close()
  15. ##########################################################################
  16. # Obtain two different shapes that has noting to to with each other
  17. m1 = brick(width=vec3(2))
  18. m2 = m1.transform(vec3(0.5, 0.3, 0.4)).transform(quat(0.7 * vec3(1, 1, 0)))
  19. # Remove the volume of the second to the first
  20. diff = difference(m1, m2)
  21. vedo.show("Boolean difference", diff, axes=14).close()
  22. ##########################################################################
  23. cube = brick(width=vec3(2))
  24. bevel(
  25. cube,
  26. [(0, 1), (1, 2), (2, 3), (0, 3), (1, 5), (0, 4)], # Edges to smooth
  27. ("width", 0.3), # Cutting description, known as 'cutter'
  28. )
  29. vedo.show("A bevel cube", cube, axes=1).close()
  30. ##########################################################################
  31. square_profile = square((O, Z), 5).flip()
  32. primitives = [
  33. ArcCentered(( 5 * X, Y), O, 10 * X),
  34. ArcCentered((15 * X, -Y), 10 * X, 20 * X),
  35. ]
  36. # Generate a path
  37. path = web(primitives)
  38. path.mergeclose()
  39. m = tube(square_profile, path)
  40. vmesh = vedo.utils.madcad2vedo(m) # <-- convert to vedo.Mesh
  41. print(vmesh)
  42. scalar = vmesh.vertices[:, 0]
  43. vmesh.cmap("rainbow", scalar, on="points").add_scalarbar(title="x-value")
  44. vedo.show("Generating a path", vmesh, axes=7).close()
  45. ##########################################################################
  46. c1 = Circle((vec3(0), Z), 1)
  47. c2 = Circle((2 * X, X), 0.5)
  48. c3 = (Circle((2 * Y, Y), 0.5), "tangent", 2)
  49. e1 = extrusion(2 * Z, web(c1))
  50. m = junction(e1, c2, c3, tangents="normal")
  51. vm = vedo.utils.madcad2vedo(m)
  52. vedo.show(vm, e1, axes=1, viewup="z").close()