Results 1 to 6 of 6
  1. #1
    hqt
    hqt is offline Member
    Join Date
    Nov 2011
    Posts
    27
    Rep Power
    0

    Question 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 :)

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default 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.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    hqt
    hqt is offline Member
    Join Date
    Nov 2011
    Posts
    27
    Rep Power
    0

    Default 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"

  4. #4
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default 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.

  5. #5
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default 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.

  6. #6
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: Take gravity of a polygon

    the object now isn't a polygon, it's an image
    I love those sliding requirements!

    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; 01-27-2012 at 12:12 PM.

Similar Threads

  1. I need help with a gravity simulator!
    By Karly_Kute_X in forum New To Java
    Replies: 5
    Last Post: 12-10-2011, 07:40 PM
  2. polygon growing
    By ericT in forum New To Java
    Replies: 1
    Last Post: 09-24-2011, 09:35 PM
  3. Polygon array?
    By AcousticBruce in forum New To Java
    Replies: 6
    Last Post: 02-05-2011, 07:38 PM
  4. Polygon won't show up
    By pizzadude223 in forum Java 2D
    Replies: 5
    Last Post: 08-09-2010, 04:51 AM
  5. how to apply gravity in tossing an egg
    By santhoshnanjappa in forum New To Java
    Replies: 1
    Last Post: 07-01-2009, 03:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •