plus half the number of lattice points on the boundary, minus 1:
A(P) = I(P) + B(P)/2 - 1
(from http://www.katev.org/maths/stands/AREA1.HTM)
So if you can figure out the area (using Newell's method, see any good graphics textbook such as Foley & Van Dam or Rogers) and you can somehow figure out how many lattice points are intersected by the edges (not necessarily at the vertices), you can get the exact number of internal points. You could modify a Bresenham line drawing routine to increment a counter whenever it arrives at a pixel with an offset of 0.
Of course you could just scan convert the polygon and count the pixels!
Dan
Dan wrote:
Archana,
The number of pixels in a polygon is approximately equivalent to the area of the polygon. That can be a murky number as it depends on the exact shape of the polygon, screen resolution, etc., but for most purposes the area of the “ideal” polygon will be close enough provided the sides of the polygon have a reasonable number of pixels.
There is a very nice Java geometry package here:
http://geosoft.no/software/
Search for “geometry” on this page. All you need to do is add the geometry.jar file as a library to your applications. The javadoc on the web page explains each function.
I haven’t tried the polygon area function (computePolygonArea), but it looks straightforward to use.
Dan
On Mon, 2 May 2005 17:00:33 -0700, Archana Chilukuri <[EMAIL PROTECTED]> wrote:
Hi all,
Does anybody know a way to compute the number of pixels enclosed in a polygon.
thanks, Archana
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
