Re: Re: [SVG] [Batik] Polygon Area
"'Dailey, David P.' [email protected] [svg-developers]" <[email protected]> Sat, 7 Nov 2015 15:31:19 +0000
| Newsgroups | gmane.text.xml.svg.devel |
|---|---|
| Message-ID | <[email protected]> |
Wow, Domenico! That is such a neat and concise computation. I didn't know it could be so simple. It will take me a while, I think, to figure out why it would work. Does it work for concave polygons as well as convex ones? cheers David ________________________________ From: [email protected] <[email protected]> on behalf of [email protected] [svg-developers] <[email protected]> Sent: Friday, November 06, 2015 5:26 PM To: [email protected] Subject: [svg-developers] Re: [SVG] [Batik] Polygon Area The code below is JavaScript. Pass X and Y arrays of x and y points (clockwise or counterclockwise), and n number of vertices. If you need it for a path element the SVG JavaScript binding provides dedicated functions like getPointAtLength(), getPathSegAtLength(), etc. to convert the path into polygon points. function polygon_area (X, Y, n) { var area = 0, i, j = n - 1; for (i = 0; i < n; j = i++) { area += (X[j] + X[i]) * (Y[j] - Y[i]); } return Math.abs(area / 2); } Domenico ------------------------------------ Posted by: "Dailey, David P." <[email protected]> ------------------------------------ ----- To unsubscribe send a message to: [email protected] -or- visit http://groups.yahoo.com/group/svg-developers and click "edit my membership" ----