I have a sketch that can increase / decrease the number of vertices for a polygon. Right now I have a variable, "unit", which is set to 50. All of the polygons' vertices are drawn from the center of the polygon with a distance of 50 from the center. This is not what I actually want, I want all of the edges of the polygons to have the length of 50 (polygons with more vertices will be bigger than polygons with less vertices). How can I do this?
float unit = 50;
int selected = 0;
ArrayList<Polygon> polys = new ArrayList<Polygon>();
Every regular n-sided polygon can be divided into n equal triangles, which can be divded into two smaller right triangles. i found this picture illustrating it:
So we have a right triangle where we know the Side ('unit=50') and the angle between hypothenuse and adjacent (2 *PI / n). We are searching for the radius, the formula for that would then be: Radius = ( Side / 2 ) / sin( π / n )
If it's not clear just google for 'Trigonometry' or '
Circumcircle of a Polygon'
Calsign, I know that it was to improve speed but I don't know what kind of data it is. When I try to println it it gives me something that looks like gibberish: NGons$Polygon@108f8e0
Amnon.owed, thanks for doing that but I'll have to see how much I can put into the class. The sketch I have posted here is a test, the goal is to build a sketch that can generate tessellations. I'm going to have to be able to figure out where the vertices of any given polygon are in absolute space so I can't use translate / rotate.
"if Polygon is a class then what kind of data is Polygon poly = polys.get(i)? Is it still considered to be a class?" If I want to be a bit pedantic (or precise), poly has a type, which is a class named Polygon. The data pointed by (referenced by) poly is an instance of that class, an object. This instance is still also pointed by the polys array list... And as kooogy said, if every object has a default toString() method, as you saw, it isn't very explicit. You can make your own custom toString(), building a string from the fields of the class you judge important to show and returning it. This toString() implementation will be automatically called by println().
Leave a comment on PhiLho's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic