Path: utzoo!attcan!uunet!ogicse!ucsd!nosc!crash!jcs From: jcs@crash.cts.com (John Schultz) Newsgroups: comp.graphics Subject: Re: Polygon orientation test ? Message-ID: <5201@crash.cts.com> Date: 22 Oct 90 22:31:47 GMT References: <4158.272311a1@cc.curtin.edu.au> Organization: Crash TimeSharing, El Cajon, CA Lines: 56 Yes, there are at least two easy ways: 1. Use the cross product of two of the points, the sign determines the orientation (Subtract point 0 from points 1 and 2, compute the cross product between the new points 1 and 2). 2. Use the Newell method (in many graphics texts). Here's a snippet of code to get you started: if (count > 3) { /* Newell method */ orient = 0; for (i=0; i < count; i++) { if (i == (count-1)) { j = 0; } else { j = i+1; } orient += (point[i].x - point[j].x)*(point[i].y + point[j].y); } } else { /* Move to origin, and do cross product */ d1.x = point[1].x - point[0].x; d1.y = point[1].y - point[0].y; d2.x = point[2].x - point[1].x; d2.y = point[2].y - point[1].y; orient = d1.x*d2.y - d1.y*d2.x; } /* if count > 3 */ /* Right handed coordinate system with +z into screen */ sgnorient = sgn(orient); if (sgnorient < 0) { /* do counter-clockwise case */ } else if (sgnorient > 0) { /* do clockwise case */ } else { /* Polygon is a line segment or point (coplaner points) */ } /* if */ Hope this helps, John