# How can I retrieve polygons with respective vertices from a PShape?

**URL:** <https://discourse.processing.org/t/how-can-i-retrieve-polygons-with-respective-vertices-from-a-pshape/986>\
**Category:** Coding Questions\
**Created:** [June 15, 2018, 10:20am UTC](https://discourse.processing.org/t/how-can-i-retrieve-polygons-with-respective-vertices-from-a-pshape/986 "2018-06-15T10:20:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cumulus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cumulus/32/451_2.png) [@cumulus](https://discourse.processing.org/u/cumulus)\
**Post date:** [June 15, 2018, 10:20am UTC](https://discourse.processing.org/t/how-can-i-retrieve-polygons-with-respective-vertices-from-a-pshape/986/1 "2018-06-15T10:20:37Z")

</div>

I would like to be able to retrieve all individual polygons from a PShape object (preferably an imported .obj) in order to know which vertices are linked to each other.

for example if I was to import a simple tetrahedron i would like to retrieve the indices of the vertices linked to a vertex with a given index.

since a tetrahedron has 4 vertices this should give me something like this:

> vertex 0 is linked to the vertices 1, 2, 3  
> vertex 1 is linked to the vertices 0, 2, 3  
> vertex 2 is linked to the vertices 1, 0, 3  
> vertex 3 is linked to the vertices 0, 1, 2

This could theoretically be achieved by checking which vertices are contained in which polygon, but I have no idea what methods to use for that or if an appropriate method even exists. Anybody got any suggestions?

**EDIT** : So I figured out that

`PShape.getChild(index)`

returns a PShape that consists of the polygon at the index.  
Calling

`getVertex()`

on that PShape returns the 3 vertices of that Polygon so that’s a step forward.  
Stil, what I would like to do is to know which Vertex is attached to which Polygon globally in order to see which Vertices are neighbors. Hope somebody can help me out 🙂

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [June 20, 2018, 5:29pm UTC](https://discourse.processing.org/t/how-can-i-retrieve-polygons-with-respective-vertices-from-a-pshape/986/2 "2018-06-20T17:29:47Z")

</div>

It sounds like you want to be to do the kinds of operations typical of a mesh library. Will you be working with triangles specifically, or any arbitrary polygon?

Here is an interesting related past discussion

> **[Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/27866/how-to-compute-3d-delaunay-triangulation-with-or-without-library/p1)**
>
> Processing is an electronic sketchbook, a language and a worldwide community. This is its forum.

These might be worth checking out to see if they already have tools to solve your problem:

- Mesh by Lee Byron
- Toxiclibs by Karsten Schmidt
- iGeo by Satoru Sugihara
- Hemesh (WBlut)

---

<div class="post-metadata">

**Author:** ![cumulus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cumulus/32/451_2.png) [@cumulus](https://discourse.processing.org/u/cumulus)\
**Post date:** [June 21, 2018, 6:54pm UTC](https://discourse.processing.org/t/how-can-i-retrieve-polygons-with-respective-vertices-from-a-pshape/986/3 "2018-06-21T18:54:09Z")

</div>

Hey @jeremydouglass,

Thanks for your reply. The toxi.geom package seems very promising! I’ll check it out.
