1

Given a sequence of (integer, integer) points, say (p1, ..., pn), which define the lines (p_i, p_i+1) for 1 <= i < n, plus the line (p_n, p_1). The resulting lines have the additional property that they don't intersect pairwise. What would be the best way to calculate the resulting volume?

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
Jo So
  • 25,005
  • 6
  • 42
  • 59
  • 1
    Just to clarify: You are asking for an algorithm to calculate the area of a 2D polygon, right? Have you looked at the relevant [Wikipedia article](http://en.wikipedia.org/wiki/Polygon#Area_and_centroid)? – thiton Dec 05 '11 at 15:13
  • Duplicate of http://stackoverflow.com/questions/451426/how-do-i-calculate-the-surface-area-of-a-2d-polygon. – Per Dec 05 '11 at 15:32
  • @thiton thanks for pointing to the right direction. – Jo So Dec 05 '11 at 16:22

1 Answers1

2

Here is a nice code blurb with explanations as to why it works: http://alienryderflex.com/polygon_area/

//  Public-domain function by Darel Rex Finley, 2006.

double polygonArea(double *X, double *Y, int points) {

  double  area=0. ;
  int     i, j=points-1  ;

  for (i=0; i<points; i++) {
    area+=(X[j]+X[i])*(Y[j]-Y[i]); j=i; }

  return area*.5; }

You should also read the previous incarnation of this question: How do I calculate the area of a 2d polygon?

Community
  • 1
  • 1
PengOne
  • 48,188
  • 17
  • 130
  • 149