Article View: comp.os.msdos.programmer
Article #377Re: Polygon Question...
From: Jim Hargrove
Date: Tue, 11 Aug 1992 14:15
Date: Tue, 11 Aug 1992 14:15
24 lines
1492 bytes
1492 bytes
In article <thompson.713120498@daphne.socsci.umn.edu>, thompson@atlas.socsci.umn.edu (T. Scott Thompson) writes:
|> morley@camins.camosun.bc.ca writes:
|>
|> >Ok, this should be an easy one... Given 3 X,Y points that form a triangle,
|> >what is the simplest (fastest) way to determine if they are clock-wise or
|> >counter-clock-wise? I'm not interested in general polygons of N points,
|> >just plain old triangles. Yes, this is for use in a graphics app.
|>
|> Try this. Calculate
|>
|> (X1 - X3)*(Y2 - Y3) - (X2 - X3)*(Y1 - Y3)
|>
|> If the result is
|>
|> positive then 1 -> 2 -> 3 traverses the triangle counter-clockwise.
|>
|> negative then 1 -> 2 -> 3 traverses the triangle clockwise
|>
|> zero then 1, 2, and 3 lie on a straight line.
This is a good test, but subject to numerical instability when the triangle is a "sliver." There isn't anything better. Just be careful.
--
-- jwh
Technical Details
Message-ID:
<1992Aug11.141545.14643@asc.slb.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!ut-emx!slcs.slb.com!asc.slb.com!nobelium!hargroveReferences:
<1992Jul21.094844.1@camins.camosun.bc.ca> <thompson.713120498@daphne.socsci.umn.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!ut-emx!slcs.slb.com!asc.slb.com!nobelium!hargrove From: hargrove@nobelium.SLCS.SLB.COM (Jim Hargrove) Newsgroups: comp.os.msdos.programmer Subject: Re: Polygon Question... Message-ID: <1992Aug11.141545.14643@asc.slb.com> Date: 11 Aug 92 14:15:45 GMT References: <1992Jul21.094844.1@camins.camosun.bc.ca> <thompson.713120498@daphne.socsci.umn.edu> Sender: hargrove@nobelium (Jim Hargrove) Organization: Schlumberger Austin Systems Center Lines: 24 Nntp-Posting-Host: nobelium