Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Java Help

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-09-2007, 02:05 AM
extreme extreme is offline
Newbie
 
Join Date: Apr 2007
Posts: 1
Rep Power: 0
extreme is on a distinguished road
Default How to calculate the number of pixels in a polygon

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.

Last edited by extreme; 04-09-2007 at 02:27 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-10-2007, 07:17 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,470
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-13-2007, 10:38 AM
DevilsCharm's Avatar   
DevilsCharm DevilsCharm is offline
Programming God
 
Join Date: Jul 2006
Posts: 887
Rep Power: 14
DevilsCharm is on a distinguished road
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-13-2007, 12:23 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

A polygon can be chopped into triangles, and use standard formulas for their area.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-13-2007, 08:46 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,470
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Yes, a *gon with x sides can be divided up into x-2 triangles whose area can easily be calculated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-17-2007, 11:34 AM
Lawtonfogle's Avatar   
Lawtonfogle Lawtonfogle is offline
Newbie
 
Join Date: Apr 2007
Posts: 8
Rep Power: 0
Lawtonfogle is on a distinguished road
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A polygon's area and volume calculate rxl_171 Visual Basic Programming 5 08-08-2007 11:01 AM
Number Cloning Ronin Java Help 3 12-21-2006 08:23 AM
I need to generate a random number in PHP dirkfirst PHP Forum 7 07-05-2006 10:58 PM


All times are GMT -5. The time now is 11:37 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads