[mapserver-users] Finding the area of a polygon

Riccardo Cohen rcohen at dial.oleane.com
Wed May 2 16:19:39 PDT 2001


>> If not, does anyone know of an algorithm for computing the area based on a variable number of points?

This is C code but really easy to read :

points[] is an array of vectors, the first is the origin of the polygon, and the other are vectors relatives to the first point. To have the area, the first point is not needed.



  double surface=0;
  long   idx;
  if (is_closed() && point_nb>2)
  {
    // all points are delta from first -> don't need first
    for (idx=2;idx<point_nb;idx++)
      surface+= // det 2d
        (points[idx-1] || points[idx])/2.0 ;
  }
  return(fabs(surface));


det 2d is computed with the following method:

	x*v.y-y*v.x



-- 
Riccardo Cohen

Articque
Les Roches
37230 Fondettes
France
email = rcohen at dial.oleane.com
web = http://www.articque.com
tel: +33 02 47 49 90 49
fax: +33 02 47 49 91 49



More information about the MapServer-users mailing list