In java, I am trying to create an irregular Polygon of n sides. The side lengths and total perimeter are known. What is the best way to calculate the coordinates of this polygon?
Creating Polygon
Started by coiner, Jan 07 2010 10:39 PM
8 replies to this topic
#1
Posted 07 January 2010 - 10:39 PM
|
|
|
#2
Posted 08 January 2010 - 06:26 AM
coiner said:
In java, I am trying to create an irregular Polygon of n sides. The side lengths and total perimeter are known. What is the best way to calculate the coordinates of this polygon?
Well, I don't know if this is what you wanted...
public double getMeasure(){
for(int i = 0; i <= numOfPoints-2; i++){
area += (xPoints[i]*yPoints[i+1])-(xPoints[i+1]*yPoints[i]);
}
area /= 2;
if(area < 0)
area *= -1;
return area;
}
#3
Posted 08 January 2010 - 12:46 PM
No i do not want to calculate the area of a preexisting polygon, i want to construct an irregular polygon out of lines.
for example, the function looks like makePolygon(int nSides, int[] sideLengths)
how would i (mathematically) get the coordinates of the polygon's vertices?
for example, the function looks like makePolygon(int nSides, int[] sideLengths)
how would i (mathematically) get the coordinates of the polygon's vertices?
#4
Posted 08 January 2010 - 01:07 PM
There are multiple ways to make an irregular polygon, given only the side lengths. Are you looking for one with maximal area, does it need to be convex, etc?
#5
Posted 08 January 2010 - 01:10 PM
i'm looking for maximal area but if you would like to share algorithms for convex as well i would appreciate it.
#6
Posted 08 January 2010 - 01:45 PM
The easiest way I can think of to get a polygon is to start with a triangle with the same perimeter, where each side has length equal to the sum of a subset of the side lengths. Then you can start "distorting" one side at a time based on making one "line" a proper line. This will involve shifting vertices around to preserve side lengths.
The geometry of this is likely to get quite complicated. I suspect (but have not proven) that the optimal area will correspond to a polygon where the vertices are all on a circle. However, side length and arc length don't correlate terribly well, so I'm not sure how much that will help you construct the actual polygon.
The geometry of this is likely to get quite complicated. I suspect (but have not proven) that the optimal area will correspond to a polygon where the vertices are all on a circle. However, side length and arc length don't correlate terribly well, so I'm not sure how much that will help you construct the actual polygon.
#7
Posted 08 January 2010 - 05:01 PM
That's a good idea and I will try it out. I can simply use this method and then check against what the total area should be. I'm sure with some tweaking I'll get it down. I'll post the results.
#8
Posted 15 June 2010 - 09:16 PM
This is where trigonometry comes in... you can easilly move around a quadrant as long as you provide the sin and cos values as well as thye length of the move. You don't have to worry about closing the polygon, this is done automatically for you. Read more on the Polygon object in the Java API.
#9
Posted 15 June 2010 - 10:34 PM
I'm not that good with geometry (anymore). But Something with the max area covered will always approach a circle. So i'm wondering if you could get the size of the circle first. Put the first point on it. And then simply draw the next lines at the place where it will intersect with the circle, and if that turns out to be the largest area covered... Really interesting.... Gonna try this out next thursday / friday :D
Will see if it's even possible to find the size of the circle first...
Will see if it's even possible to find the size of the circle first...


Sign In
Create Account

Back to top









