code: def convex_hull(*args, polygon=True):
      """The convex hull surrounding the Points contained in the list of entities.
  
      Parameters
      ==========
  
      args : a collection of Points, Segments and/or Polygons
  
      Optional parameters
      ===================
  
      polygon : Boolean. If True, returns a Polygon, if false a tuple, see below.
                Default is True.
  
      Returns
      =======
  
      convex_hull : Polygon if ``polygon`` is True else as a tuple `(U, L)` where
                    ``L`` and ``U`` are the lower and upper hulls, respectively.
  
      Notes
      =====
  
      This can only be performed on a set of points whose coordinates can
      be ordered on the number line.
  
      See Also
      ========
  
      sympy.geometry.point.Point, sympy.geometry.polygon.Polygon
  
      Examples
      ========
  
      >>> from sympy import convex_hull
      >>> points = [(1, 1), (1, 2), (3, 1), (-5, 2), (15, 4)]
      >>> convex_hull(*points)
      Polygon(Point2D(-5, 2), Point2D(1, 1), Point2D(3, 1), Point2D(15, 4))
      >>> convex_hull(*points, **dict(polygon=False))
      ([Point2D(-5, 2), Point2D(15, 4)],
       [Point2D(-5, 2), Point2D(1, 1), Point2D(3, 1), Point2D(15, 4)])
  
      References
      ==========
  
      .. [1] https://en.wikipedia.org/wiki/Graham_scan
  
      .. [2] Andrew's Monotone Chain Algorithm
        (A.M. Andrew,
        "Another Efficient Algorithm for Convex Hulls in Two Dimensions", 1979)
        https://web.archive.org/web/20210511015444/http://geomalgorithms.com/a10-_hull-1.html
  
      """
      from .line import Segment
      from .polygon import Polygon
  
      p = OrderedSet()
      for e in args:
          if not isinstance(e, GeometryEntity):
              try:
                  e = Point(e)
              except NotImplementedError:
                  raise ValueError(
                      "%s is not a GeometryEntity and cannot be made into Point"
                      % str(e)
                  )
          if isinstance(e, Point):
              p.add(e)
          elif isinstance(e, Segment):
              p.update(e.points)
          elif isinstance(e, Polygon):
              p.update(e.vertices)
          else:
              raise NotImplementedError(
                  "Convex hull for %s not implemented." % type(e)
              )
  
      # make sure all our points are of the same dimension
      if any(len(x) != 2 for x in p):
          raise ValueError(
              "Can only compute the convex hull in two dimensions"
          )
  
      p = list(p)
      if len(p) == 1:
          return p[0] if polygon else (p[0], None)
      elif len(p) == 2:
          s = Segment(p[0], p[1])
          return s if polygon else (s, None)
  
      def _orientation(p, q, r):
          """Return positive if p-q-r are clockwise, neg if ccw, zero if
          collinear."""
          return (q.y - p.y) * (r.x - p.x) - (q.x - p.x) * (r.y - p.y)
  
      # scan to find upper and lower convex hulls of a set of 2d points.
      U = []
      L = []
      try:
          p.sort(key=lambda x: x.args)
      except TypeError:
          raise ValueError("The points could not be sorted.")
      for p_i in p:
          while len(U) > 1 and _orientation(U[-2], U[-1], p_i) <= 0:
              U.pop()
          while len(L) > 1 and _orientation(L[-2], L[-1], p_i) >= 0:
              L.pop()
          U.append(p_i)
          L.append(p_i)
      U.reverse()
      convexHull = tuple(L + U[1:-1])
  
      if len(convexHull) == 2:
          s = Segment(convexHull[0], convexHull[1])
          return s if polygon else (s, None)
      if polygon:
          return Polygon(*convexHull)
      else:
          U.reverse()
          return (U, L)
  
imports: from collections import deque
  from math import sqrt
  from sympy import nsimplify
  from .entity import GeometryEntity
  from .exceptions import GeometryError
  from .point import Point, Point2D, Point3D
  from sympy.core.containers import OrderedSet
  from sympy.core.exprtools import factor_terms
  from sympy.core.function import Function, expand_mul
  from sympy.core.numbers import Float
  from sympy.core.sorting import ordered
  from sympy.core.symbol import Symbol
  from sympy.core.singleton import S
  from sympy.polys.polytools import cancel
  from sympy.functions.elementary.miscellaneous import sqrt
  from sympy.utilities.iterables import is_sequence
  from mpmath.libmp.libmpf import prec_to_dps
label_desc: Use image node_id 7 for calling a global function with example usage: convex_hull() and returns: unknown, unknown, unknown, Polygon, U,  L, unknown