Hi there,
I have a java program in which i draw a polygon in a JPanel using the Polygon class. I want to calculate the number of pixels in this polygon (or the area of the polygon in pixels). Can anyone please help me on this. I have tried a lot but couldnt find a way to do this.
Thanks.
How to calculate the number of pixels in a polygon
Started by
Guest_extreme_*
, Apr 08 2007 10:05 PM
5 replies to this topic
#1
Guest_extreme_*
Posted 08 April 2007 - 10:05 PM
Guest_extreme_*
|
|
|
#2
Posted 10 April 2007 - 03:17 PM
Finding the area of the polygon in pixels is no different than finding the area of the polygon in inches or feet. Just apply the correct formula substituting the dimensions you specified when you drew the polygon.
#3
Posted 13 April 2007 - 06:38 AM
I believe it has to be a regular polygon for most formulas to work. I remember learning about this in geometry, something about the number of sides minus two... that was in there somewhere. I wish I could remember! Luckily, there's a tool I found online that can help me in sticky situations like this. It's called Google, it's new and I'm loving it. Oh yeah! The apothem! The forumula is area = (Apothem)(Perimeter)/2 Now it's coming back.
Areas and Perimeters of Regular Polygons
Regular polygon area formula - Math Open Reference
That's the good stuff.
Areas and Perimeters of Regular Polygons
Regular polygon area formula - Math Open Reference
That's the good stuff.
#4
Posted 13 April 2007 - 08:23 AM
A polygon can be chopped into triangles, and use standard formulas for their area.
#5
Posted 13 April 2007 - 04:46 PM
Yes, a *gon with x sides can be divided up into x-2 triangles whose area can easily be calculated.
#6
Posted 17 April 2007 - 07:34 AM
It would depend of the screen though. So calculate the area (either cm^2 or in.^2), and then add a coversion factor that says so many cm^2/in.^2 equal so many pixels. As for the pixel count, that you would just have to count. Happy counting.


Sign In
Create Account

Back to top










