Path: utzoo!attcan!uunet!microsoft!davidle From: davidle@microsoft.UUCP (David LEVINE) Newsgroups: comp.graphics Subject: Re: clockwise or counter-clockwise 2d polygons Message-ID: <58503@microsoft.UUCP> Date: 25 Oct 90 02:07:31 GMT References: <1990Oct22.114039.8799@jarvis.csri.toronto.edu> Reply-To: davidle@microsoft.UUCP (David LEVINE) Organization: Microsoft Corp., Redmond WA Lines: 29 In article <1990Oct22.114039.8799@jarvis.csri.toronto.edu> corkum@csri.toronto.edu (Brent Thomas Corkum) writes: >This routine and sample program computes whether a 2D polygon is clockwise >or counter-clockwise. The function takes vertices passed in an array >(x1,y1,x2,y2,...xn,yn where n=#vertices) and the number of vertices. >Of course for a 3D polygon, clockwise or counter-clockwise depends I believe that it would be much easier to use the simple formula which computes the AREA of the polygon and then look at the resulting sign. For a clockwise polygon, the area is: sum ( ( x(i) - x(i-1) ) * ( ( y(i) + y(i-1) ) ) / 2 Where x(i),y(i) and x(i-1),y(i-1) are adjacent pairs of points going clockwise around the polygon. If the sum comes out negative then the polygon was counter-clockwise. Of course, if you only want the area then don't bother to divide by two. This is much easier to code, although it is possible that for very long, thin or otherwise strange polygons, some special case code might be better. Similarly, this formula is not guarenteed to work with polygons that have crossed edges (I don't know what is defined to be clockwise then, anyway). I posted the derivation of the area formula sometime last year. DLL