// Calculate the area of an irregular polygon defined // by a series of x,y coordinates, and plot it. // The bounding line must go counter-clockwise. // Note - the line must not cross over itself or the // overlapped part will be subtracted from the area. Data 1,2, 1,3, 2,5, 1,5, -1,5, -2,4, Data -3,1, -1,-1, -1,1 DIM points (20,2) graph read x1, y1 i = 0 startx = x1: starty=y1 points (i,0) = x1: points (i,1) = y1 i = i+1 while (read (0)) read x2, y2 points (i,0) = x2: points (i,1) = y2 i = i+1 sum = sum + (x2+x1)/2 * (y2-y1) x1 = x2 y1 = y2 wend x2 = startx: y2=starty // end point = start point sum = sum + (x2+x1) * (y2-y1) / 2 shape polypoints=points, polycount=i, fillcolor=(255,128,128) shape polygon print: print "Area = ";sum