volume of a zone defined by two polygon bases
13486
def vol(poly1, poly2):
    "
    c_point = central_p(poly1, poly2)
    c_point = (c_point[0], c_point[1], c_point[2])
    vol_therah = 0
    num = len(poly1)
    poly1.append(poly1[0])
    poly2.append(poly2[0])
    for i in range(num - 2):
        # the upper part
        tehrahedron = [c_point, poly1[0], poly1[i+1], poly1[i+2]]
        vol_therah += vol_tehrahedron(tehrahedron)
        # the bottom part
        tehrahedron = [c_point, poly2[0], poly2[i+1], poly2[i+2]]
        vol_therah += vol_tehrahedron(tehrahedron)
    # the middle part
    for i in range(num):
        tehrahedron = [c_point, poly1[i], poly2[i], poly2[i+1]]
        vol_therah += vol_tehrahedron(tehrahedron)
        tehrahedron = [c_point, poly1[i], poly1[i+1], poly2[i]]
        vol_therah += vol_tehrahedron(tehrahedron)
    return vol_therah
920545
def areas(self):
        
        v1 = self.points[self.simplices[:,1]] - self.points[self.simplices[:,0]]
        v2 = self.points[self.simplices[:,2]] - self.points[self.simplices[:,1]]

        area = 0.5*(v1[:,0]*v2[:,1] - v1[:,1]*v2[:,0])
        return area
456189
def polygon_diameter(points):
    ''' 
    '''
    return max(point_dist(p0, p1) for (p0, p1) in combinations(points, 2))
95972
def polygon(self, vertexes, attr=0, row=None):
        ''
        self.polylines.append((vertexes + [vertexes[0]], attr, row))
1234685
double calculateHypervolumeIndicator(Solution<?> solutionA, Solution<?> solutionB, int d,
      double maximumValues[], double minimumValues[]) {
    double a, b, r, max;
    double volume ;
    double rho = 2.0;

    r = rho * (maximumValues[d - 1] - minimumValues[d - 1]);
    max = minimumValues[d - 1] + r;

    a = solutionA.getObjective(d - 1);
    if (solutionB == null) {
      b = max;
    } else {
      b = solutionB.getObjective(d - 1);
    }

    if (d == 1) {
      if (a < b) {
        volume = (b - a) / r;
      } else {
        volume = 0;
      }
    } else {
      if (a < b) {
        volume =
            calculateHypervolumeIndicator(solutionA, null, d - 1, maximumValues, minimumValues) * (b
                - a) / r;
        volume +=
            calculateHypervolumeIndicator(solutionA, solutionB, d - 1, maximumValues, minimumValues)
                * (max - b) / r;
      } else {
        volume =
            calculateHypervolumeIndicator(solutionA, solutionB, d - 1, maximumValues, minimumValues)
                * (max - a) / r;
      }
    }

    return (volume);
  }
443711
private static double getSegDistSq(double px, double py, Coordinate a, Coordinate b) {
        double x = a.x;
        double y = a.y;
        double dx = b.x - x;
        double dy = b.y - y;

        if (dx != 0f || dy != 0f) {
            double t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);

            if (t > 1) {
                x = b.x;
                y = b.y;
            } else if (t > 0) {
                x += dx * t;
                y += dy * t;
            }
        }

        dx = px - x;
        dy = py - y;

        return dx * dx + dy * dy;
    }
198320
def bbox2wktpolygon(bbox):
    

    minx = float(bbox[0])
    miny = float(bbox[1])
    maxx = float(bbox[2])
    maxy = float(bbox[3])
    return 'POLYGON((%.2f %.2f, %.2f %.2f, %.2f %.2f, %.2f %.2f, %.2f %.2f))' \
        % (minx, miny, minx, maxy, maxx, maxy, maxx, miny, minx, miny)
1336067
public static double getPolygonArea( int[] x, int[] y, int N ) {
        int i, j;
        double area = 0;

        for( i = 0; i < N; i++ ) {
            j = (i + 1) % N;
            area += x[i] * y[j];
            area -= y[i] * x[j];
        }

        area /= 2;
        return (area < 0 ? -area : area);
    }
251344
private Area getArea(double simplifyTolerance, BoundingBox boundingBox,
			ProjectionTransform transform, Polygon polygon) {

		Area area = null;

		for (LineString ring : polygon.getRings()) {

			Path2D path = getPath(simplifyTolerance, boundingBox, transform,
					ring);
			Area ringArea = new Area(path);

			if (area == null) {
				area = ringArea;
			} else {
				area.subtract(ringArea);
			}

		}

		return area;
	}
405890
def area (self):
    
    area = 0.0
    
    for segment in self.segments():
      area += ((segment.p.x * segment.q.y) - (segment.q.x * segment.p.y))/2

    return area
549992
def vol_zone(poly1, poly2):
    "
    c_point = central_p(poly1, poly2)
    c_point = (c_point[0], c_point[1], c_point[2])
    vol_therah = 0
    num = len(poly1)
    for i in range(num-2):
        # the upper part
        tehrahedron = [c_point, poly1[0], poly1[i+1], poly1[i+2]]
        vol_therah += vol_tehrahedron(tehrahedron)
        # the bottom part
        tehrahedron = [c_point, poly2[0], poly2[i+1], poly2[i+2]]
        vol_therah += vol_tehrahedron(tehrahedron)
    # the middle part
    for i in range(num-1):
        tehrahedron = [c_point, poly1[i], poly2[i], poly2[i+1]]
        vol_therah += vol_tehrahedron(tehrahedron)
        tehrahedron = [c_point, poly1[i], poly1[i+1], poly2[i]]
        vol_therah += vol_tehrahedron(tehrahedron)
    tehrahedron = [c_point, poly1[num-1], poly2[num-1], poly2[0]]
    vol_therah += vol_tehrahedron(tehrahedron)
    tehrahedron = [c_point, poly1[num-1], poly1[0], poly2[0]]
    vol_therah += vol_tehrahedron(tehrahedron)
    return vol_therah
1027044
def volume(self):
        
        volume = ((np.pi * self.primitive.radius ** 2) *
                  self.primitive.height)
        return volume
116989
def bounding_polygon(self):
        
        lon_left, lat_bottom, lon_right, lat_top = Tile.tile_coords_to_bbox(self.x, self.y, self.zoom)
        print(lon_left, lat_bottom, lon_right, lat_top)
        return Polygon([[[lon_left, lat_top],
                       [lon_right, lat_top],
                       [lon_right, lat_bottom],
                       [lon_left, lat_bottom],
                       [lon_left, lat_top]]])
1250550
function d3_geom_polygonIntersect(c, d, a, b) {
  var x1 = c[0], x2 = d[0], x3 = a[0], x4 = b[0],
      y1 = c[1], y2 = d[1], y3 = a[1], y4 = b[1],
      x13 = x1 - x3,
      x21 = x2 - x1,
      x43 = x4 - x3,
      y13 = y1 - y3,
      y21 = y2 - y1,
      y43 = y4 - y3,
      ua = (x43 * y13 - y43 * x13) / (y43 * x21 - x43 * y21);
  return [x1 + ua * x21, y1 + ua * y21];
}
903985
function() {
            if (!this.cachedBoundingBox) {
                var minpoint = new CSG.Vector3D(0, 0, 0);
                var maxpoint = new CSG.Vector3D(0, 0, 0);
                var polygons = this.polygons;
                var numpolygons = polygons.length;
                for (var i = 0; i < numpolygons; i++) {
                    var polygon = polygons[i];
                    var bounds = polygon.boundingBox();
                    if (i === 0) {
                        minpoint = bounds[0];
                        maxpoint = bounds[1];
                    } else {
                        minpoint = minpoint.min(bounds[0]);
                        maxpoint = maxpoint.max(bounds[1]);
                    }
                }
                this.cachedBoundingBox = [minpoint, maxpoint];
            }
            return this.cachedBoundingBox;
        }
84322
def bounds(self):
        """"""
        corners = [self.image_corner(corner) for corner in self.corner_types()]
        return Polygon([[corner.x, corner.y] for corner in corners])
1204512
private static boolean polygonDisjointEnvelope_(Polygon polygon_a,
			Envelope envelope_b, double tolerance,
			ProgressTracker progress_tracker) {
		// Quick rasterize test to see whether the the geometries are disjoint,
		// or if one is contained in the other.
		int relation = tryRasterizedContainsOrDisjoint_(polygon_a, envelope_b,
				tolerance, false);

		if (relation == Relation.disjoint)
			return true;

		if (relation == Relation.contains || relation == Relation.within)
			return false;

		Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D();
		polygon_a.queryEnvelope2D(env_a);
		envelope_b.queryEnvelope2D(env_b);

		if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance))
			return false;

		PolygonUtils.PiPResult pipres;
		Point2D pt_b = new Point2D();
		env_b.queryLowerLeft(pt_b);
		pipres = PolygonUtils.isPointInPolygon2D(polygon_a, pt_b, tolerance);
		if (pipres != PolygonUtils.PiPResult.PiPOutside)
			return false;

		env_b.queryLowerRight(pt_b);
		pipres = PolygonUtils.isPointInPolygon2D(polygon_a, pt_b, tolerance);
		if (pipres != PolygonUtils.PiPResult.PiPOutside)
			return false;

		env_b.queryUpperRight(pt_b);
		pipres = PolygonUtils.isPointInPolygon2D(polygon_a, pt_b, tolerance);
		if (pipres != PolygonUtils.PiPResult.PiPOutside)
			return false;

		env_b.queryUpperLeft(pt_b);
		pipres = PolygonUtils.isPointInPolygon2D(polygon_a, pt_b, tolerance);
		if (pipres != PolygonUtils.PiPResult.PiPOutside)
			return false;

		MultiPathImpl mimpl_a = (MultiPathImpl) polygon_a._getImpl();
		AttributeStreamOfDbl pos = (AttributeStreamOfDbl) (mimpl_a
				.getAttributeStreamRef(VertexDescription.Semantics.POSITION));

		Envelope2D env_b_inflated = new Envelope2D();
		env_b_inflated.setCoords(env_b);
		env_b_inflated.inflate(tolerance, tolerance);
		for (int ptIndex = 0, n = mimpl_a.getPointCount(); ptIndex < n; ptIndex++) {
			double x = pos.read(2 * ptIndex);
			double y = pos.read(2 * ptIndex + 1);
			if (env_b_inflated.contains(x, y))
				return false;
		}

		return !linearPathIntersectsEnvelope_(polygon_a, env_b, tolerance,
				progress_tracker);
	}