Skip to main content

[JAVA2D] number of pixels enclosed in a polygon

3 replies [Last post]
Anonymous

Hi all,

Does anybody know a way to compute the number of pixels enclosed in a
polygon.

thanks,
Archana

________________________________

This email message is for the sole use of the intended
recipient(s) and may contain confidential and privileged information.Any
unauthorized review, use, disclosure or distribution is prohibited. If
you are not the intended recipient, please contact the sender by reply
email and destroy all copies of the original message. If you are the
intended recipient, please be advised that the content of this message
is subject to access, review and disclosure by the sender's Email System
Administrator.

________________________________

========================================================================
=== To unsubscribe, send email to listserv@java.sun.com and include in
the body of the message "signoff JAVA2D-INTEREST". For general help,
send email to listserv@java.sun.com and include in the body of the
message "help".

--------------------------------------------------------

This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information.Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. If you are the intended recipient, please be advised that the content of this message is subject to access, review and disclosure by the sender's Email System Administrator.
--------------------------------------------------------

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Dan

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
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 listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Daniel Rice

Pick's theorem says the area of a polygon with vertices at integer
lattice points is equal to the number of lattice points in the interior,
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
> 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 listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Daniel Rice

Ignore my reference to Newell's method (memory playing tricks on me).
The formula for the area of a polygon with N vertices (x_i, y_i), 0 <=
i < N is:

A = 1/2 Sum_0^(N-1) (x_i * y_(i+1) - x_(i+1) * y_1)

Dan

Daniel Rice wrote:
> Pick's theorem says the area of a polygon with vertices at integer
> lattice points is equal to the number of lattice points in the interior,
> 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
>> 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 listserv@java.sun.com and include in the
>> body
>> of the message "signoff JAVA2D-INTEREST". For general help, send
>> email to
>> listserv@java.sun.com and include in the body of the message "help".
>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help"
> .

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".