Here is the basic formula from: http://www.geometryalgorithms.com/Archive/algorithm_0101/algorithm_0101.htm#area2D_polygon()
// area2D_Polygon(): computes the area of a 2D polygon
// Input: int n = the number of vertices in the polygon
// Point* V = an array of n+2 vertices
// with V[n]=V[0] and V[n+1]=V[1]
// Return: the (float) area of the polygon
float
area2D_Polygon( int n, Point* V )
{
float area = 0;
int i, j, k; // indices
for (i=1, j=2, k=0; i<=n; i++, j++, k++) {
area += V[i].x * (V[j].y - V[k].y);
}
return area / 2.0;
}
Here is some simple skill:
procedure(getObjectArea(obj)
let(((area 0.0) sum lastPt firstPt crdList dx dy)
case(obj~>shape
("polygon"
sum = 0
crdList = obj~>path
firstPt = lastPt = car(crdList)
foreach(crd cdr(crdList)
sum = sum + ((xCoord(crd) - xCoord(lastPt))
* (yCoord(crd) + yCoord(lastPt)))
lastPt = crd
)
sum = sum + ((xCoord(firstPt) - xCoord(lastPt))
* (yCoord(firstPt) + yCoord(lastPt)))
area = area + (0.5 * abs(sum))
)
("rectangle"
dx = xCoord(car(obj~>bBox)) - xCoord(cadr(obj~>bBox))
dy = yCoord(car(obj~>bBox)) - yCoord(cadr(obj~>bBox))
area = area + abs( dx * dy )
)
)
float(area)
)
)
Originally posted in cdnusers.org by dmay