rokicki@polya.STANFORD.EDU (Tomas G. Rokicki) (02/28/88)
/* * Takes an array containing points of a polygon, and * calculates the area. Assumes the polygon has no * crossing segments or such, and that the first point * is repeated. For instance, the unit square would * be represented by: * * pts[] = { 0, 0, * 0, 1, * 1, 1, * 1, 0, * 0, 0 } ; * n = 4 ; */ long area(pts, n) int *pts, n ; { long tot = 0 ; while (n > 0) { tot += (pts[1] + pts[3]) * (long)(pts[2] - pts[0]) ; /* (y1 + y2) * (x2 - x1) */ pts += 2 ; } if (tot < 0) tot = - tot ; return(tot / 2) ; }