code: def triangulate(vertices):
      """Triangulate a set of vertices.
  
      This uses a pure Python implementation based on [1]_.
  
      If `Triangle` by Jonathan R. Shewchuk [2]_ and the Python bindings `triangle` [3]_
      are installed, this will be used instead. Users need to acknowledge and adhere to
      the licensing terms of these packages.
  
      In the VisPy `PolygonCollection Example` [4]_ a speedup of 97% using
      `Triangle`/`triangle` can be achieved compared to the pure Python implementation.
  
      Parameters
      ----------
      vertices : array-like
          The vertices.
  
      Returns
      -------
      vertices : array-like
          The vertices.
      triangles : array-like
          The triangles.
  
      References
      ----------
      .. [1] Domiter, V. and Žalik, B. Sweep‐line algorithm for constrained
         Delaunay triangulation
      .. [2] Shewchuk J.R. (1996) Triangle: Engineering a 2D quality mesh generator and
         Delaunay triangulator. In: Lin M.C., Manocha D. (eds) Applied Computational
         Geometry Towards Geometric Engineering. WACG 1996. Lecture Notes in Computer
         Science, vol 1148. Springer, Berlin, Heidelberg.
         https://doi.org/10.1007/BFb0014497
      .. [3] https://rufat.be/triangle/
      .. [4] https://github.com/vispy/vispy/blob/main/examples/collections/polygon_collection.py
      """
      n = len(vertices)
      vertices = np.asarray(vertices)
      zmean = vertices[:, 2].mean()
      vertices_2d = vertices[:, :2]
      segments = np.repeat(np.arange(n + 1), 2)[1:-1]
      segments[-2:] = n - 1, 0
  
      try:
          import triangle  # noqa: F401
      except (ImportError, AssertionError):
          vertices_2d, triangles = _triangulate_python(
              vertices_2d, segments
          )
      else:
          segments_2d = segments.reshape((-1, 2))
          vertices_2d, triangles = _triangulate_cpp(
              vertices_2d, segments_2d
          )
  
      vertices = np.empty((len(vertices_2d), 3))
      vertices[:, :2] = vertices_2d
      vertices[:, 2] = zmean
      return vertices, triangles
  
imports: from __future__ import division, print_function
  from itertools import permutations
  import numpy
  from collections import OrderedDict
label_desc: Use image node_id 3 for calling a global function with example usage: triangulate(vertices) and returns: vertices,  triangles