Re: How to calculate the area of a polygon?
- To: mathgroup at smc.vnet.net
- Subject: [mg27733] Re: [mg27712] How to calculate the area of a polygon?
- From: Tomas Garza <tgarza01 at prodigy.net.mx>
- Date: Tue, 13 Mar 2001 03:52:51 -0500 (EST)
- References: <200103120709.CAA23252@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
The problem is not so difficult (if you can calculate the area of a triangle) in the case of convex polygons. A recursion can be set up in order to add the area of successive triangles. E.g., if area[tri] is your function to calculate the area of a triangle tri, then In[1]:= ft[3] = Area[Polygon[{data[[1]], data[[2]], data[[3]]}]]; ft[n_] := ft[n - 1] + Area[Polygon[{data[[1]], Last[Take[data, n - 1]], data[[n]]}]]; will work very nicely. However, since you want to consider the non-convex case too, you are in trouble, unless you get hold of a copy of Tom Wickham-Jones' book Mathematica Graphics and install the package ExtendGraphics which comes with it. Among other very nice and useful things it has a subpackage called ExtendGraphics`NonConvexTriangulate` which will solve your problem in a jiffy. Essentially, what it does is to triangulate your polygon maintaining its shape, so that you just have to calculate the area of each of the resulting triangles and add them together. In your problem, for example, if you modify the abscissa in the last pair, so as to make the polygon non-convex, i.e., In[2]:= data Out[2]= {{0, 0}, {5, 0}, {10, 5}, {0, 10}, {5, 5}} you may obtain the area as follows: In[3]:= Needs["ExtendGraphics`NonConvexTriangulate`"] In[4]:= nverts = NonConvexTriangulate[data] Out[4]= {{1, 2, 3}, {3, 4, 5}, {3, 5, 1}} In[5]:= Plus @@ Map[Area[Polygon[Part[data, #]]] &, nverts] Out[5]= 75/2 Tomas Garza Mexico City ----- Original Message ----- From: "liwen liwen" <gzgear at yahoo.com> To: mathgroup at smc.vnet.net Subject: [mg27733] [mg27712] How to calculate the area of a polygon? > Dear friends, > > I want to calculate the area of a polygon, for > example, the polygon is defined by following points: > data={{0,0},{5,0},{10,5},{0,10},{-5,5}}; > Regardless of that it is concave or convex. > > Any help is appreciated. > > Thank you very much! > > Liwen 3/11/2001 > > E-mail: gzgear at yahoo.com > > __________________________________________________ > Do You Yahoo!? > Yahoo! Auctions - Buy the things you want at great prices. > http://auctions.yahoo.com/ >
- References:
- How to calculate the area of a polygon?
- From: liwen liwen <gzgear@yahoo.com>
- How to calculate the area of a polygon?