Results 1 to 6 of 6
Thread: Take gravity of a polygon
 01272012, 10:17 AM #1Member
 Join Date
 Nov 2011
 Posts
 27
 Rep Power
 0
Take gravity of a polygon
I'm trying to use MouseMove Event to rotate a polygon. But, (with my algorithm), I need to know what gravity of an image. I don't know in Java has a function for my work or I must do by myself ?
If Java doesn't have this function. What your idea about this ? (take gravity of a polygon). My solution uses some Mathematical background. (sum of vectors).
Please give me your idea.
thanks :)
 01272012, 10:22 AM #2
Re: Take gravity of a polygon
To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem. Indicate what the present program does, and what you would like it to do.
Just remember the first 'S' stands for short.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 01272012, 10:59 AM #3Member
 Join Date
 Nov 2011
 Posts
 27
 Rep Power
 0
Re: Take gravity of a polygon
Oh, sorry for my poor English :(
Maybe the true title for my problem is: "which Java function return centre of Gravity of a Polygon"
 01272012, 11:44 AM #4Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,712
 Rep Power
 13
Re: Take gravity of a polygon
There is no method in the Polygon class (that I know of). But the centroid can be calculated from the coordinates of each of the vertices. See, eg, Centroid  Wikipedia, the free encyclopedia.
 01272012, 11:59 AM #5Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,712
 Rep Power
 13
Re: Take gravity of a polygon
Notice that the centroid of a polygon is *not* the mean of it vertices considered as vectors. You can see this by considering a square whose centroid is its center. Now form a polygon by adding lots of points all very near the top edge of the square. The mean value of the vertices will now be very near the top edge although the polygon is still more or less a square and its centroid shouldn't have changed.
 01272012, 12:05 PM #6Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,712
 Rep Power
 13
Re: Take gravity of a polygon
the object now isn't a polygon, it's an image
Now you *can* take the mean position of all the pixels in the image. I'm no expert but I don't see that any speed up is possible in general  only if there is some symmetry to the image.
[Edit] No that's wrong. You don't need symmetry you just need to approximate the image area with simple geometries like straight lines. Eg approximate it with a polygon and proceed as before.Last edited by pbrockway2; 01272012 at 12:12 PM.
Similar Threads

I need help with a gravity simulator!
By Karly_Kute_X in forum New To JavaReplies: 5Last Post: 12102011, 07:40 PM 
polygon growing
By ericT in forum New To JavaReplies: 1Last Post: 09242011, 08:35 PM 
Polygon array?
By AcousticBruce in forum New To JavaReplies: 6Last Post: 02052011, 07:38 PM 
Polygon won't show up
By pizzadude223 in forum Java 2DReplies: 5Last Post: 08092010, 03:51 AM 
how to apply gravity in tossing an egg
By santhoshnanjappa in forum New To JavaReplies: 1Last Post: 07012009, 02:26 PM
Bookmarks