On Wed, 16 Apr 2008 19:43:05 GMT, Roedy Green

<(E-Mail Removed)> wrote, quoted or indirectly quoted

someone who said :

>see http://mindprod.com/jgloss/sort.html

>

>If the class that describes the points does not support a natural

>Comparable ordering, extend the class and write one, or implement an

>Comparator. see http://mindprod.com/jgloss/comparable.html

>http://mindprod.com/jgloss/comparator.html
To determine clockwise order you might use a hanging moss algorithm

to find a line segment that leaves from the current spot.

http://mindprod.com/jgloss/hangingmoss.html
If you allow absolutely no slop, i.e. have integral co-ordinates and

insist on the next segment leaving from precisely where the previous

left off, you can so something simpler.

Create two HashMaps,'a's and 'b's. Put the start endpoints in one and

the end endpoints in the other.

Make up some arbitrary rule to decide which end is the A and B end.

Then look in both the a and b hashmap for a match to the current

point. You will find two points, yourself and one other (if this is

indeed a closed polygon). You know where you are, so you only need

look in the other set. (A toggle boolean might be helpful).

This presumes that no three line segments meet at a common point.

Chase the segments until you get back where you started.

When done do the test in your textbook to determine if what you have

is clockwise. If not, reverse it.

--

Roedy Green Canadian Mind Products

The Java Glossary

http://mindprod.com