Extract all data points whose element centroid lies within the given
        polygon.

        Parameters
        ----------

        Returns
        -------
971783
def extract_polygon_area(self, pid, polygon_points):
        
        polygon = shapgeo.Polygon(polygon_points)
        xy = self.grid.get_element_centroids()
        in_poly = []
        for nr, point in enumerate(xy):
            if shapgeo.Point(point).within(polygon):
                in_poly.append(nr)

        values = self.parsets[pid][in_poly]
        return np.array(in_poly), values
799403
def connectedVertices(self, index, returnIds=False):
        
        mesh = self.polydata()

        cellIdList = vtk.vtkIdList()
        mesh.GetPointCells(index, cellIdList)

        idxs = []
        for i in range(cellIdList.GetNumberOfIds()):
            pointIdList = vtk.vtkIdList()
            mesh.GetCellPoints(cellIdList.GetId(i), pointIdList)
            for j in range(pointIdList.GetNumberOfIds()):
                idj = pointIdList.GetId(j)
                if idj == index:
                    continue
                if idj in idxs:
                    continue
                idxs.append(idj)

        if returnIds:
            return idxs
        else:
            trgp = []
            for i in idxs:
                p = [0, 0, 0]
                mesh.GetPoints().GetPoint(i, p)
                trgp.append(p)
            return np.array(trgp)
142198
def within(self, region):
        
        mask = numpy.array([
            geometry.Point(rec['lon'], rec['lat']).within(region)
            for rec in self.array])
        return self.filter(mask)
350514
def point(self):
        
        if not self.geometry:
            raise ValueError('geometry attribute must be set before trying to get point property')
        if self.geometry.geom_type == 'Point':
            return self.geometry
        else:
            try:
                # point_on_surface guarantees that the point is within the geometry
                return self.geometry.point_on_surface
            except GEOSException:
                # fall back on centroid which may not be within the geometry
                # for example, a horseshoe shaped polygon
                return self.geometry.centroid
1158504
function getCenter(points) {
        var center = {x: 0, y: 0};
        for (var i =0; i < points.length; ++i ) {
            center.x += points[i].x;
            center.y += points[i].y;
        }
        center.x /= points.length;
        center.y /= points.length;
        return center;
    }
512107
def centerOfMass(self):
        
        cmf = vtk.vtkCenterOfMass()
        cmf.SetInputData(self.polydata(True))
        cmf.Update()
        c = cmf.GetCenter()
        return np.array(c)
694626
def within(self, x, ctrs, kdtree=None):
        """"""

        if kdtree is None:
            # If no KDTree is provided, execute a brute-force search
            # over all cubes.
            idxs = np.where(np.max(np.abs(ctrs - x), axis=1) <= self.hside)[0]
        else:
            # If a KDTree is provided, find all points within r (`hside`).
            idxs = kdtree.query_ball_point(x, self.hside, p=np.inf, eps=0)

        return idxs
244901
def contains(polygon, point):
        
        in_hole = functools.reduce(
            lambda P, Q: P and Q,
            [interior.covers(point) for interior in polygon.interiors]
        ) if polygon.interiors else False
        return polygon.covers(point) and not in_hole
547277
def update_centroids_from_list(self, list_values):
        
        [self.update(value['m'], value['c']) for value in list_values]
        return self
81255
public static final Atom getCenterVector(Atom[] atomSet, Atom centroid){

		double[] coords = new double[3];
		coords[0] = 0 - centroid.getX();
		coords[1] = 0 - centroid.getY();
		coords[2] = 0 - centroid.getZ();

		Atom shiftVec = new AtomImpl();
		shiftVec.setCoords(coords);
		return shiftVec;

	}
263592
def moments_central(self):
        

        ycentroid, xcentroid = self.cutout_centroid.value
        return _moments_central(self._filtered_data_zeroed,
                                center=(xcentroid, ycentroid), order=3)
93645
def _retain_centroids(numbers, thres):
    """"""
    numbers.sort()
    prev = -1
    ret = []
    for n in numbers:
        if prev < 0 or n - prev > thres:
            ret.append(n)
            prev = n
    return ret
377941
def Wm(self):
        
        centroids = self.get_element_centroids()

        Wm = scipy.sparse.csr_matrix(
            (self.nr_of_elements, self.nr_of_elements))
        # Wm = np.zeros((self.nr_of_elements, self.nr_of_elements))
        for i, nb in enumerate(self.element_neighbors):
            for j, edges in zip(nb, self.element_neighbors_edges[i]):
                # side length
                edge_coords = self.nodes['presort'][edges][:, 1:]
                edge_length = np.linalg.norm(
                    edge_coords[1, :] - edge_coords[0, :]
                )
                distance = np.linalg.norm(centroids[i] - centroids[j])

                # main diagonal
                Wm[i, i] += edge_length / distance
                # side diagonals
                Wm[i, j] -= edge_length / distance
        return Wm
930387
def _centroids(self, verts):
        
        '''
        value = sp.zeros([len(verts), 3])
        for i, i_verts in enumerate(verts):
            value[i] = np.mean(i_verts, axis=0)
        return value
54821
private static Point2D computePolygonCentroid(Polygon polygon)
    {
        int pathCount = polygon.getPathCount();

        if (pathCount == 1) {
            return getPolygonSansHolesCentroid(polygon);
        }

        double xSum = 0;
        double ySum = 0;
        double areaSum = 0;

        for (int i = 0; i < pathCount; i++) {
            int startIndex = polygon.getPathStart(i);
            int endIndex = polygon.getPathEnd(i);

            Polygon sansHoles = getSubPolygon(polygon, startIndex, endIndex);

            Point2D centroid = getPolygonSansHolesCentroid(sansHoles);
            double area = sansHoles.calculateArea2D();

            xSum += centroid.x * area;
            ySum += centroid.y * area;
            areaSum += area;
        }

        return new Point2D(xSum / areaSum, ySum / areaSum);
    }
910761
def allPolygons(self):
        
        polygons = self.polygons[:]
        if self.front: 
            polygons.extend(self.front.allPolygons())
        if self.back: 
            polygons.extend(self.back.allPolygons())
        return polygons
229149
public PointExpression<Point> centroid() {
        if (centroid == null) {
            centroid = GeometryExpressions.pointOperation(SpatialOps.CENTROID, mixin);
        }
        return centroid;
    }