We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › How to compute area for a Java polygon class
Page Index Toggle Pages: 1
How to compute area for a Java polygon class? (Read 944 times)
How to compute area for a Java polygon class?
Jul 17th, 2007, 8:08pm
 
Dear all,

I have a GP script that generates several rectangular spaces that altogether constitute a floor plan. I found very useful to use the Java Rectangle2D class cause I have the option to check directly for collisions with other overlapping rectangles. Then I used the Java polygon class in order to create a single object that describes the floor plan as a whole. My question is if there is a method that calculates the area of a Java polygon or a Java area class. For instance it is extremely easy to check if a certain point is contained within a particular polygon by just using the contains(point) method. Does anyone know something similar for the area? If not I guess I have to write my own method
Angry

Thanks.. Smiley
Re: How to compute area for a Java polygon class?
Reply #1 - Jul 17th, 2007, 11:58pm
 
I'm not sure if I understand you, but I've wrote a example how to use the java.awt.polygon class in processing:

http://www.processinghacks.com/hacks/using-awt-s-polygon-class-to-test-for-insideness



Re: How to compute area for a Java polygon class?
Reply #2 - Jul 18th, 2007, 12:09am
 
thanks a lot for your reply Smiley but unfortunately this is not what I'm looking for Sad My question is if there is a method that calculates the area of a java.awt.polygon.

Thanks anyways
Re: How to compute area for a Java polygon class?
Reply #3 - Jul 18th, 2007, 10:33am
 
i havent used awt.polygon, but i think you could write your area computation method by taking the polygon's vertices

check this our for some math

http://www.mathgoodies.com/lessons/vol1/area_triangle.html
Re: How to compute area for a Java polygon class?
Reply #4 - Jul 18th, 2007, 11:01am
 
I belive http://mathworld.wolfram.com/PolygonArea.html has the simplest formula for this that you're likely to find.  It doesn't appear that awt.polygon has a method for this, which seems a bit ridiculous to me as it would seem to be natural for it to have...in any case, the formula in that link should be easy to implement.
Re: How to compute area for a Java polygon class?
Reply #5 - Jul 18th, 2007, 12:56pm
 
yap it seems..strange to me as well that an area method is not contained in the awt. It's true it is very easy to write your own method. The only thing is that the polygon should not intersect itself Angry

It seems that a more generic method, would be to use the polygon's pathIterator interface to go through the segments it returns. In the same time to check for self-intersection and if that's the case to calculate the sum area as the result of the areas of the sub-polygons. Angry But I'm not sure..

Anyway,
thank you all guys Smiley
Page Index Toggle Pages: 1