The Union of reals and removal of duplicates

• To: mathgroup at smc.vnet.net
• Subject: [mg8290] The Union of reals and removal of duplicates
• From: Russell Towle <rustybel at foothill.net>
• Date: Sun, 24 Aug 1997 04:46:31 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Hi all, I have posted questions in the past concerning the Union of real
numbers.  This has continued to be an issue for me, but I have succeeded in
finding solutions for some applications of this Union.  For instance,
consider the problem of, given an arbitrary Graphics3D polyhedron in
Mathematica, to obtain a list of its vertices, with duplicates dropped; a
list of its polygons, as a list of lists of indices into its vertices; and
a list of its edges, as a list of lists of indices into its vertices.  Here
is my solution, where "obj" has been defined, perhaps, as

obj = Polyhedron [ Dodecahedron ]; (*needs the Graphics "polyhedra" package*)

(*****)
Length [h = Level [obj, {-2}] ]; (*how many vertices altogether?*)
Length [g = Union [ r = Rationalize [h, 10^-2] ] ]; (*how many distinct?*)

(*now, what are the indices of the distinct in the altogether?*)
s = Table [Flatten [Position[ r, x_ /; x==g[[i]] ] ], { i, Length [g] } ];

(*go back and get the un-rationalized distinct vertices*)
v = h [[ Map[ First[#]&, s] ] ]; (*vertices*)
(*****)

So far so good.  If there is a better, especially faster, way of
accomplishing this, I would be pleased to know it.  Below I find the
polygons bounding the polyhedron "obj," and proceed to transform them into
a list of indices into the vertices, "v."  I overwrite some previous
variables, such as h, but use some previous variables, such as g (the
Rationalized Union of vertices).

(*****)
Length [h = Level [obj, {-3}] ]; (*how many  polygons altogether?*)
h = Rationalize[ h, 10^-2]; (*rationalize them*)

(*now, what are the indices of the distinct in each polygon?*)
s = Table[ Position[ h, x_ /; x==g[[i]] ], {i, Length [g]} ];

(*This gives the indices into g (hence 'v') of the polygons h*)
gons = Table [qq = Position [s, x_List /; First[x]==j ];
Map[ #[]&, Sort[
Table[ Join[{s[[ qq[[i,1]],qq[[i,2]] ]] []},{qq[[i,1]]} ],
{i, Length[qq]}] ] (*Sort ends here*)
], (*Map ends here*)
{j, Length[h]}];
(*****)

Finally, with the polygons construed as lists of indices into vertices,
find the edges, and remove duplicates.  The slowest and most problematical
part of all code is the Table below, given the not very descriptive name,
"c."  The indices have already been split into pairs, and it only remains
to find and discard all those cases where the indices {i,j} reappear as
{j,i}.  When a polyhedron is very complex (has over, say, twenty or thirty
faces), this Table of Positions can take a very very long time to create.

(*****)
(*find face indices and make edge indices*)
rings = Map[Join[#,{First[#]}]&, gons ];(*add first index to end of list*)
edges = Flatten[ Map[ Partition[#,2,1]&, rings], 1];(*break into pairs*)

(*remove duplicates (indices in reverse order)*)
c=Table[
Position[edges, x_ /; x == edges[[i]] || x == Reverse[edges[[i]]] ],
{i,Length[edges]}];
f=Map[Take[#,1]&, Union[c]];
f=Flatten[f,2];
(*****)

I have used these methods to build a function, wherein an arbitrary
Mathemtica polyhedron is written to POV-Ray format, with spheres on every
vertex, cylinders on every edge, and the faces divided into triangles as
POV likes them.  I will post this to MathSource as soon as I find out how
to speed up the removal of edge duplicates.

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: Locating text in Show
• Next by Date: RungeKutta
• Previous by thread: Re: Simplifying Sqrt[a^2*d^2] -> a*d
{"ft_lang_label":"__label__en","ft_lang_prob":0.8795588,"math_prob":0.94260234,"size":3726,"snap":"2023-40-2023-50","text_gpt3_token_len":1009,"char_repetition_ratio":0.11955938,"word_repetition_ratio":0.059210528,"special_character_ratio":0.32313472,"punctuation_ratio":0.17456022,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9925186,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-01T10:47:42Z\",\"WARC-Record-ID\":\"<urn:uuid:e804646b-fdf4-4c9a-877b-3a523c044805>\",\"Content-Length\":\"47310\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7509e7cd-51f0-43d4-b825-ff59a8eb0926>\",\"WARC-Concurrent-To\":\"<urn:uuid:c76a6b12-6449-437f-b3da-eb905baab398>\",\"WARC-IP-Address\":\"140.177.9.73\",\"WARC-Target-URI\":\"https://forums.wolfram.com/mathgroup/archive/1997/Aug/msg00164.html\",\"WARC-Payload-Digest\":\"sha1:GNQDQC5HKERTW4KHCCKOYJZOFCGW3KST\",\"WARC-Block-Digest\":\"sha1:2FQKZO7YZIEMEQ4QGZKKFGMM6HHRDURA\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100286.10_warc_CC-MAIN-20231201084429-20231201114429-00739.warc.gz\"}"}