Parsing polygons: A good solution

• To: mathgroup at smc.vnet.net
• Subject: [mg9072] Parsing polygons: A good solution
• From: Russell Towle <rustybel at foothill.net>
• Date: Thu, 9 Oct 1997 01:42:51 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```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]&) @
Partition[Join[RotateRight[#],{Null,Null,Null}],2])
)&,
Sort[((Chop[Rationalize[(facent at #),10^-2]])@#&/@ (trip1)),
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:  rustybel at foothill.net
------------------------------

```

• Prev by Date: RE: TraceInternal and
• Next by Date: Re: weird Log[0] *0 result
• Previous by thread: RE: TraceInternal and
• Next by thread: Re: weird Log[0] *0 result