14 Replies Latest reply on Oct 26, 2007 4:43 AM by ethanDC

# find the center of an irregular polygon

Does any one have code that can determine the center of an irregular 3 sided polygon?
Using a bounding box does not work.
If you know how to draw one using the center point as the registration point that would be great.
Thanks,
Ethan
• ###### 1. Re: find the center of an irregular polygon
that's a triangle. there is no one center. there are several different centers of various types that can be defined depending upon the property being sought. what are you looking for?
• ###### 2. Re: find the center of an irregular polygon
I have got some code that randomly generates an irregular triangle.
When I click on the stage I want the center of the triangle created where I click.
I am no sure what the several types of centers are that you refer to but If I were to rotate the triangle I want it to appear to rotate around it's center "balance" point.
I guess another center would be based on boundry dimensions but that is not
what I am looking for. Also, instead of moving the triangle after it is created,
I want to create it with the center point as the registration point so that it will
rotate around that point.
Thanks, Ethan
• ###### 3. Re: find the center of an irregular polygon
the most common triangle centers are the orthocenter, centroid, incenter and circumcenter. and you appear to want none of those. i think you want the triangle's center of gravity. is that correct?
• ###### 4. Re: find the center of an irregular polygon
Hi kglad - I think he wants the centroid, which AFAIK is also the center of
mass? I think the centroid would provide the best spot to rotate on...

--
Dave -
http://www.blurredistinction.com

• ###### 5. Re: find the center of an irregular polygon
if you want the coordinates of the centroid (which is the center of mass for a uniform triangle), take the average of the vertices.
• ###### 6. Re: find the center of an irregular polygon
Will taking the average of the vertices give me the center of mass for a NON uniform triangle? If so can you point me to some sample code that then draws the triangle from that center point.
Thanks, Ethan
• ###### 7. Re: find the center of an irregular polygon
1. no. but what you mean by uniform is probably not the same as what i mean. so, what is it that you mean by non-uniform?

2. there is no "the triangle" given a centroid. there are infinitely many triangles with a given centroid.
• ###### 8. Re: find the center of an irregular polygon
When I say non uniform I mean the sides are all of unequal length. And when I say " the triangle" I mean the triangle that will be created by the random
set of points that I create when I click the screen. So I guess I need to store those points and then some how reverse engineer where the center of that specific triangle would be and then somehow draw the triangle
from that reverse engineered center point. That way I will be able to rotate it from its center of mass. Sorry if I was not clear before.
Thanks,EC
• ###### 9. Re: find the center of an irregular polygon
that's still a uniform triangle. you can click anywhere on-stage to define the centroid, then randomly generate any two points (that will constitute 2 triangle vertices and where neither can be the same as the centroid) and then determine the third vertice so the resulting triangle has a centroid equal to the place you clicked on-stage.
• ###### 10. Re: find the center of an irregular polygon
OK, let me see what I can come up with and then I'll post the code.
Thanks again,
Ethan
• ###### 11. Re: find the center of an irregular polygon
you're welcome.
• ###### 12. Re: find the center of an irregular polygon
Here is some code that works. It relys on a few custom classes found in Colin Moock's Essential Actionscript 3.0 book
as noted in the code. However, the way to center the irregular sided triangle is shown.