MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Triangle List <-> Adjacency List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30507] Re: [mg30466] Triangle List <-> Adjacency List
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Fri, 24 Aug 2001 04:06:09 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Here are a couple of quick attempts. However, I have not tested them on 
anything but your example, so there may be a bug (I am pretty sure that 
the first function, which is the one you seem to care more about is 
O.K.):

TrianglesToAdj[l_List] :=
   Module[{Side, sides, vertices = Union[Flatten[l]], adj},
     SetAttributes[Side, Orderless];
     sides = Union[
         Side @@@ Flatten[Map[Partition[Append[#, First[#]], 2, 1] &, l], 
1]];
     adj[x_] := Cases[sides, Side[a_, x] -> a, Infinity]; Map[adj, 
vertices]]

AdjToTriangles[adj_List] :=
   Module[{verts = Union[Flatten[adj]], sides, Side},
     SetAttributes[Side, Orderless];
     sides = Union[
         Side @@@
           Flatten[Distribute[#, List] & /@ Transpose[{verts, adj}], 1]];
     ReplaceList[
       sides, {___, Side[i_, j_], ___, Side[i_, k_], ___,
           Side[j_, k_], ___} -> {i, j, k}]]

In your case they work fine:

In[3]:=
tlist={{0,2,1},{1,2,3}};

In[4]:=
ad=TrianglesToAdj[tlist]


Out[4]=
{{1,2},{0,2,3},{0,1,3},{1,2}}

In[5]:=
AdjToTriangles[ad]

Out[5]=
{{0,1,2},{1,2,3}}


On Thursday, August 23, 2001, at 03:15  PM, Kashif Rasul wrote:

> Hi there,
>
> I was wondering if anyone knows of a quick way of converting a list of
> triangle corners, eg. for a triangulation like:
>
>     0        1
>     o------o
>     |      /|
>     |     / |
>     |    /  |
>     |   /   |
>     |  /    |
>     | /     |
>     |/      |
>     o------o
>     2         3
>
> the triangle list will be {{0,2,1},{1,2,3}}, i.e. the first triangle's
> first corner is at index [1], followed by its other two corners in
> counterclockwise order etc.; into a list which represents the adjacency
> structure of the graph, e.g. for the above triangulation, it will be:
> {{1,2},{0,2,3},{0,1,3},{1,2}}, node 0 is conected to node 1 and 2, etc.
>
> Also it might be helpfull to go the other way too from an adjacency list
> to a triangle list.
>
> Thank you in advance.
>
> Kashif
>
>
>

Andrzej Kozlowski
Toyama International University
JAPAN
http://platon.c.u-tokyo.ac.jp/andrzej/


  • Prev by Date: RE: Re: Problem with context creation in packages
  • Next by Date: Re: Plot Joined Intelligently
  • Previous by thread: Triangle List <-> Adjacency List
  • Next by thread: Point Size and Plot Symbols