# Substituting the element of a list into a list that contains the index position

I see similar questions for lists and indexes and manipulating with Thread, MapIndexed,etc., but I do not see how to do a substitution.

I have a list of coordinates for a geometric object and a list of the vertices that make up the face of the geometric object which is simply the index to the coordinates list.

I broke them out for convenience initially thinking it would be simple to substitute the coordinates back into the vertices for the face.

I see several examples on mathematica documentation for MapIndexed, but don't understand how to apply them to this "substitution".

Any explanation and/or help would be appreciated. I have attached the sample code below.

groupedVerticesRT =
{
{
{   C4, C4, C4}, {  C4, C4, -C4}, {   C4, -C4, C4}, {
C4, -C4, -C4},
{-C4, C4, C4}, {-C4, C4, -C4}, {-C4, -C4, C4}, {-C4, -C4, -C4}
},
{
{0, C6, C5}, {0, C6, -C5}, {0, -C6, C5}, {0, -C6, -C5}
},
{
{C5, 0, C6}, {C5, 0, -C6}, {-C5, 0, C6}, {-C5, 0, -C6}
},
{
{C6, C5, 0}, {C6, -C5, 0}, {-C6, C5, 0}, {-C6, -C5, 0}
},
{
{0, C4, C6}, {0, C4, -C6}, {0, -C4, C6}, {0, -C4, -C6},
{C6, 0, C4}, {C6, 0, -C4}, {-C6, 0, C4}, {-C6, 0, -C4},
{C4, C6, 0}, {C4, -C6, 0}, {-C4, C6, 0}, {-C4, -C6, 0}
}
};
facesRT =
{
{13, 23, 15, 21}, {13, 23, 3, 25}, {13, 25, 1, 21}, {25, 18, 30,
3}, {25, 17, 29, 1},
{25, 18, 26, 17}, {18, 30, 4, 26}, {17, 26, 2, 29}, {29, 1, 21,
9}, {21, 5, 27, 15},
{15, 27, 7, 23}, {21, 9, 31, 5}, {5, 31, 19, 27}, {27, 20, 32,
7}, {27, 19, 28, 20},
{23, 7, 32, 11}, {23, 11, 30, 3}, {32, 20, 28, 8}, {11, 32, 12,
30}, {22, 14, 26, 2},
{19, 31, 6, 28}, {14, 24, 4, 26}, {9, 29, 10, 31}, {32, 8, 24,
12}, {12, 24, 4, 30},
{29, 2, 22, 10}, {10, 22, 6, 31}, {28, 16, 24, 8}, {28, 6, 22,
16}, {16, 22, 14, 24}
};

Edit: I would like to return something like the following using MapIndexed or something similar to substitute the coordinates into the list for the faces to generate one giant list that has a list of faces made up of a the list of their coordinates:

expandedRT =
{
{
{C5, 0, C6}, {0, -C4, C6}, {-C5, 0, C6}, {0, C4, C6} (* coordinates {13, 23, 15, 21} *)
}, (* face 1 *)
{
(* faces 2 - end *)
}
}

coords = Flatten[groupedVerticesRT, 1];

expandedRT = ReplaceAll[i_Integer :> coords[[i]]] @ facesRT

Alternatively, you can use Extract:

expandedRT2 = Extract[coords, List /@ facesRT];

expandedRT2 == expandedRT
True

What you are searching is "GraphicsComplex".

Here is an example:

coordinates = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0.5, 0.5, 1}};

surfaces = {{1, 2, 3}, {1, 2, 4}, {2, 3, 4}, {1, 3, 4}};

A tetrahedron by surfaces:

Graphics3D[GraphicsComplex[coordinates, Polygon /@ surfaces] ]

The same can be achieved by:

Graphics3D[GraphicsComplex[coordinates, Triangle /@ surfaces] ]

If you only want 2 of the surfaces:

Graphics3D[GraphicsComplex[coordinates, Triangle /@ surfaces[[1 ;; 2]]] ]

If you want to replace indices by coordinates by hand, you may simply write:

coordinates[[#]] & /@ surfaces

(* {{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}, {{0, 0, 0}, {1, 0, 0}, {0.5, 0.5,
1}}, {{1, 0, 0}, {0, 1, 0}, {0.5, 0.5, 1}}, {{0, 0, 0}, {0, 1,
0}, {0.5, 0.5, 1}}} *)
• Maybe I didn't explain well at all what I was trying to do. I was hoping to find an automatic way to do what you describe in the last part of your answer. I was using Graphics3D and Polygon already for mapping, but I wanted to perform some operations across the entire list of coordinates (in the order of the faces) to make parametrized versions of the faces. In that context, the manual way of the last part of your answer would work, but I wouldn't want to do it for every polyhedron I work with. Commented Feb 11, 2023 at 18:42

Taking cues from the answer by @kglr:

coords = Flatten[groupedVerticesRT, 1];
rules = MapIndexed[First@#2 -> #1 &, coords];

Now either Lookupor ReplaceAll can be used:

Lookup[rules, #] & /@ facesRT

Or

ReplaceAll[facesRT, rules]