intersect2d.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. """Find the overlap area of 2 triangles"""
  2. from vedo import Mesh, precision, show
  3. import numpy as np
  4. verts1 = [(1.9, 0.50), (2.1, 0.8), (2.4, 0.4)]
  5. verts2 = [(2.3, 0.75), (1.7, 0.4), (2.1, 0.3)]
  6. faces = [(0,1,2)]
  7. m1 = Mesh([verts1, faces]).c('g').lw(4).wireframe()
  8. m2 = Mesh([verts2, faces]).c('b').lw(4).wireframe()
  9. a1 = precision(m1.area(),3) + " :mum:^2"
  10. a2 = precision(m2.area(),3) + " :mum:^2"
  11. fp1 = m1.flagpole('Triangle 1\nA=' + a1,
  12. point=(2.1,0.7), s=0.012, offset=(-0.3,0.04))
  13. fp2 = m2.flagpole('Triangle 2\nA=' + a2,
  14. point=(1.9,0.4), s=0.012, offset=(0.2,-0.2))
  15. m3 = m1.clone().wireframe(False).c('tomato').lw(0)
  16. zax = (0,0,1)
  17. v0,v1,v2 = np.insert(np.array(verts2), 2, 0, axis=1)
  18. m3.cut_with_plane(origin=v0, normal=np.cross(zax, v1-v0))
  19. if m3.npoints:
  20. m3.cut_with_plane(origin=v1, normal=np.cross(zax, v2-v1))
  21. if m3.npoints:
  22. m3.cut_with_plane(origin=v2, normal=np.cross(zax, v0-v2))
  23. fp3 = m3.flagpole('Overlap polygon\nA=' + precision(m3.area(),3),
  24. point=(2.2,0.6), s=0.012)
  25. show(m1, m2, m3, fp1, fp2, fp3, __doc__, axes=1, size=(800,600), zoom=1.3).close()