#NEWLINE# def centroid( * args ) : #NEWLINE# #INDENT# 'Find the centroid (center of mass) of the collection containing only Points,\n    Segments or Polygons. The centroid is the weighted average of the individual centroid\n    where the weights are the lengths (of segments) or areas (of polygons).\n    Overlapping regions will add to the weight of that region.\n\n    If there are no objects (or a mixture of objects) then None is returned.\n\n    See Also\n    ========\n\n    sympy.geometry.point.Point, sympy.geometry.line.Segment,\n    sympy.geometry.polygon.Polygon\n\n    Examples\n    ========\n\n    >>> from sympy import Point, Segment, Polygon\n    >>> from sympy.geometry.util import centroid\n    >>> p = Polygon((0, 0), (10, 0), (10, 10))\n    >>> q = p.translate(0, 20)\n    >>> p.centroid, q.centroid\n    (Point2D(20/3, 10/3), Point2D(20/3, 70/3))\n    >>> centroid(p, q)\n    Point2D(20/3, 40/3)\n    >>> p, q = Segment((0, 0), (2, 0)), Segment((0, 0), (2, 2))\n    >>> centroid(p, q)\n    Point2D(1, -sqrt(2) + 2)\n    >>> centroid(Point(0, 0), Point(2, 0))\n    Point2D(1, 0)\n\n    Stacking 3 polygons on top of each other effectively triples the\n    weight of that polygon:\n\n        >>> p = Polygon((0, 0), (1, 0), (1, 1), (0, 1))\n        >>> q = Polygon((1, 0), (3, 0), (3, 1), (1, 1))\n        >>> centroid(p, q)\n        Point2D(3/2, 1/2)\n        >>> centroid(p, p, p, q) # centroid x-coord shifts left\n        Point2D(11/10, 1/2)\n\n    Stacking the squares vertically above and below p has the same\n    effect:\n\n        >>> centroid(p, p.translate(0, 1), p.translate(0, -1), q)\n        Point2D(11/10, 1/2)\n\n    ' #NEWLINE# from sympy.geometry import Polygon , Segment , Point #NEWLINE# if args : #NEWLINE# #INDENT# if all ( ( isinstance ( g , Point ) for g in args ) ) : #NEWLINE# #INDENT# c = Point ( 0 , 0 ) #NEWLINE# for g in args : #NEWLINE# #INDENT# c += g #NEWLINE# #UNINDENT# den = len ( args ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if all ( ( isinstance ( g , Segment ) for g in args ) ) : #NEWLINE# #INDENT# c = Point ( 0 , 0 ) #NEWLINE# L = 0 #NEWLINE# for g in args : #NEWLINE# #INDENT# l = g . length #NEWLINE# c += ( g . midpoint * l ) #NEWLINE# L += l #NEWLINE# #UNINDENT# den = L #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if all ( ( isinstance ( g , Polygon ) for g in args ) ) : #NEWLINE# #INDENT# c = Point ( 0 , 0 ) #NEWLINE# A = 0 #NEWLINE# for g in args : #NEWLINE# #INDENT# a = g . area #NEWLINE# c += ( g . centroid * a ) #NEWLINE# A += a #NEWLINE# #UNINDENT# den = A #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# c /= den #NEWLINE# return c . func ( * [ i . simplify ( ) for i in c . args ] )