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

# Parsing polygons: A good solution

3 views
Skip to first unread message

### Russell Towle

unread,
Oct 9, 1997, 3:00:00 AM10/9/97
to

Hi all,

With respect to the problem I posed concerning removing from a list, those
polygons which fall into coincidence in pairs in 3-space, Xah Lee provided
an excellent solution, although I have yet to understand in detail how it
works. His solution and my much slower one depend upon a function,
"facent," which returns the centroid of a polygon.

Here it is, applied to a list of polygons named "trip1":

trip2=Nest[
(
(DeleteCases[#,Null,{1}]&) @ (Flatten[#,1]&) @
((If[SameQ@@(Head/@#),Null,#]&) /@
Partition[Join[RotateRight[#],{Null,Null,Null}],2])
)&,
Sort[((Chop[Rationalize[(facent@#),10^-2]])@#&/@ (trip1)),
OrderedQ[{Head@#1,Head@#2}]&],
2
]/.({___}[li_List]:>li);

Xah's method is about 8 times faster than my previous fastest method, below:

centfaces=Map[Rationalize[facent[#],10^-3]&, trip1];
h=Table[
g=centfaces[[i]];
Position[ Map[g==#&,centfaces],x_ /; x==True],
{i,Length[centfaces]}];
red=Flatten[ Select[h ,Length[#]==1&]];
trip2=trip1[[red]];

Russell Towle
Giant Gap Press: books on California history, digital topographic maps
P.O. Box 141
Dutch Flat, California 95714
------------------------------
Voice: (916) 389-2872
e-mail: rust...@foothill.net
------------------------------

0 new messages