How to sort polygon vertices anticlockwise

This is a discussion on How to sort polygon vertices anticlockwise within the Game Programming forums, part of the General Programming Boards category; Good afternoon, I need an algorithm to sort the vertices of a polygon in an anticlockwise order. I know it's ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    19

    How to sort polygon vertices anticlockwise

    Good afternoon,

    I need an algorithm to sort the vertices of a polygon in an anticlockwise order. I know it's rather simple (everything is!) but I get confused every time I try to do it.

    C code or pseudocode would be fine.

    Thanks,
    Duetti

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Are you given just a random set of points that make up a polygon? If so there would be more than one way to form the polygon so I'm not sure "sorting them anti-clockwise" would work so easily. Is there more to the problem? Are your polygons limited to the convex case?
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    You don't sort them in anti-clockwise or clockwise. Create the object with the sort order in mind and then let your 3D art proggy do the rest.

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    19
    >Are you given just a random set of points that make up a polygon?
    Yes, a random set of points that has been entered by the user.

    >Are your polygons limited to the convex case?
    Yes they are.

    If the vertices are sorted anticlockwise then I can easily "fill" the polygon. Right now I demand that the user inputs the vertices in a specific order (anticlockwise).

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    19
    > You don't sort them in anti-clockwise or clockwise. Create the object with the sort order in mind and then let your 3D art proggy do the rest.

    Are you some kind of a moron? The "3D art proggy" will be virtually useless if it can not reorder the vertices.

    Programming is not about writing code that nobody undestands (let alone use in other projects) so that you can impress your friends. As for the code fragments that you posted on one of the threads that I started (about linear interpolation), they suck. Completely unstructured, variables spawning in different parts of the code.

    Get a proper education on the subject and then try to educate others.

    I've also read a couple of them tutorials published on this site....(sigh)...zero modularity, zero reusability, don't quit your days jobs.

    Anyway, I've overcome my problems (clipping,shading,etc) so all of you net nerds can kiss my ass. :-)

    Duetti

  6. #6
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Good luck getting help talking to people like that.

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    19
    Attention BMJ, he he he

    I've done what I wanted to do, so there is no reason to ask for anyone's help nor will I ever attempt to ask for help on forum's like this since they seem to be occupied mainly by immature programmer-wannabes, net nerds that use irony to mask their inability to debate and showoffs.

    I just like to say out loud what some of you don't want to admit.

    Duetti

  8. #8
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Debate? What debate? You asked a question, two people offered help. I don't care about your other threads, I was originally concerned with this one, the question at hand here. It is an act of kindness to want to help. Telling people to kiss your ass, asking if they're idiots, telling people their code sucks, and suggesting that you don't really need anyone's lowly help at all, tells me that you're the immature showoff. </thinking out loud>

  9. #9
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Watch out, BMJ. He's an internet tough-guy. He might beat you up .

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    bump.flames.closed = true;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 04:03 AM
  2. Point in polygon test - spherical coords
    By bhdz in forum C Programming
    Replies: 1
    Last Post: 11-07-2007, 12:25 PM
  3. threaded merge sort
    By AusTex in forum Linux Programming
    Replies: 4
    Last Post: 05-04-2005, 04:03 AM
  4. IDEA: Polygon unions and intersections
    By Magos in forum Contests Board
    Replies: 3
    Last Post: 05-21-2003, 07:16 PM
  5. Shell Sort vs Heap Sort vs Quick Sort
    By mackol in forum C Programming
    Replies: 6
    Last Post: 11-22-2002, 07:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21