Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Clockwise/Counterclockwise?

0 views
Skip to first unread message

Michael Simpson

unread,
Feb 3, 1998, 3:00:00 AM2/3/98
to

Esri's documentation states that polygons are clockwise or
counter-clockwise depending on whether you are modeling an item or a
hole in the item respectively. My questions is, given an arbitrary
array of coordinates, following the rules of:
The rings are closed.
The order of the rings in the point array are not significant.
Polygons must be clean. (They don't cross themselves.)

How do you determine whether the polygon is clockwise or
counter-clockwise.

Thank you,
Michael Simpson
t_ms...@qualcomm.com

ian gillespie

unread,
Feb 3, 1998, 3:00:00 AM2/3/98
to

I think this refers to the direction in which the verticies have been
digitized/generated etc. There's a "from node" and a "to node" with a
series of verticies delineating any arc/polygon giving it a clockwise
or counter clockwise direction.


Ian Gillespie
WID-Geomatics Unit
Environment Canada
(opinions expressed are mine)

Mark Cederholm

unread,
Feb 3, 1998, 3:00:00 AM2/3/98
to

> My questions is, given an arbitrary
>array of coordinates, following the rules of:
> The rings are closed.
> The order of the rings in the point array are not significant.
> Polygons must be clean. (They don't cross themselves.)
>
>How do you determine whether the polygon is clockwise or
>counter-clockwise.
>

Assuming you're working in ArcView, the Polygon.Make request automatically
orients the rings correctly, whatever the input point list is. Nonetheless,
if you're interested in testing a particular ring the following Avenue
script should do the trick:

' Ring.IsClockwise

' Determines if ring is clockwise
' Adapted from p. 26 of Computational Geometry in C by Joseph O'Rourke

' Arguments: plist = list of points representing ring
' Returns: Boolean (or nil if polygon is degenerate)

plist = SELF.Get(0)

sum = 0
p0 = plist.Get(0)
a0 = p0.GetX
a1 = p0.GetY
i = 1
n = plist.Count - 1
while (i < n)
p1 = plist.Get(i)
p2 = plist.Get(i+1)
b0 = p1.GetX
b1 = p1.GetY
c0 = p2.GetX
c1 = p2.GetY
sum = sum + (a0 * b1) - (a1 * b0) + (a1 * c0) - (a0 * c1) + (b0 * c1) -
(c0 * b1)
i = i + 1
end
if (sum = 0) then
return nil
else
return (sum < 0)
end


The following script gives an example of executing the test:

out_name = FileName.GetCWD.MakeTmp("Report","txt")
out_name = FileDialog.Put(out_name, "*.txt", "Output Report")
if (out_name = nil) then return nil end
lf = LineFile.Make(out_name, #FILE_PERM_WRITE)
theFTab = av.GetActiveDoc.GetActiveThemes.Get(0).GetFTab
theShapeField = theFTab.FindField("Shape")
for each r in theFTab
thePoly = theFTab.ReturnValue(theShapeField,r)
i = 0
for each ring in thePoly.AsPolyLine.AsList
IsCW = av.Run("Ring.IsClockwise",{ring}).AsString
recno = r.AsString
ringno = i.AsString
numv = ring.Count.AsString
outrec = "Polygon"++recno++"Ring"++ringno++"Vertices"++numv+":
clockwise ="++IsCW
lf.WriteElt(outrec)
i = i + 1
end
end
lf.close

--Mark


0 new messages