<p>Draw it twice, first time at full size and the color you want for the outline, draw it filled. The second time you draw it scaled down in both the x and y directions. The second time you draw it the color is the same as the background color, and draw it filled again. What will be left is the outline. Is this what you had in mind?</p>
<p>Per your comment, I add more info:</p>
<p>Generating an array of exterior edges can be done in a few ways. The easiest one to implement (but also the slowest) is to count the number polygons that share a given edge. The exterior is all the edges which only have a single polygon using that edge. And the two vertices that make up that edge become part of the array of &quot;lines&quot;( an actual line can be computed from two vertices). Also, this will count &quot;holes&quot; as part of the exterior. For example if a building surrounds a courtyard, then the courtyard would be counted as exterior.</p>
<p>This can be implemented by creating an array of unique vertices, then each polygon is formed by indexing into the list. (just like indexed triangle draw lists). Finally pick a single polygon off the list, takes its first edge, and search all the other polygons for that edge.</p>
<p>Another method using a doubly connected edge list is given <a href="https://stackoverflow.com/questions/26103138/find-the-outline-of-adjacent-polygons">here</a>.</p>

CC BY-SA 4.0
2021-03-29T05:56:24.923Z
That would solve it as in it would draw the outline. Although in my case (kind of an edge case I guess) I want an array of lines that together form the outline
munHunger
CC BY-SA 4.0
2021-03-29T14:47:24.643Z
I updated my answer per your comment.
pmw1234
CC BY-SA 4.0
2021-03-27T19:28:31.723Z
2021-03-29T14:47:10.593Z
2021-03-29T14:47:10.593Z
pmw1234
<p>I hope this is the right forum to ask this question.</p>
<p>I want to experiment with procedurally generating some buildings, and as a first step I want to generate a 2D shape to use as a foundation for the building.</p>
<p>My plan would be to create a union of an arbitrary (but probably quite small) amount of shapes.
It seems simple enough, but I wonder what algorithms there are available for breaking up such a union into simple line shapes? (that can be used to place walls)</p>

CC BY-SA 4.0
2021-03-28T11:34:02.280Z
Here is a good tutorial for OpenGL on how to create outlines for arbitrary objects using the stencil buffer: [learnopengl -> stencil-testing](https://learnopengl.com/Advanced-OpenGL/Stencil-testing). I think this technique can be translated to other APIs like DirectX or Vulkan. However, it is a bit more complicated than the answer of pmw1234 and probably too much for your use case.
wychmaster
<algorithm><geometry>
getting the outline of an arbitrary set of shape unions
munHunger
# getting the outline of an arbitrary set of shape unions

(Asked by: username_0 on 2021-03-25)

I hope this is the right forum to ask this question.

I want to experiment with procedurally generating some buildings, and as a first step I want to generate a 2D shape to use as a foundation for the building.

My plan would be to create a union of an arbitrary (but probably quite small) amount of shapes.
It seems simple enough, but I wonder what algorithms there are available for breaking up such a union into simple line shapes? (that can be used to place walls)

**Tags:** algorithm, geometry

> **Comments:**
> **username_1**: Here is a good tutorial for OpenGL on how to create outlines for arbitrary objects using the stencil buffer: [learnopengl -> stencil-testing](https://learnopengl.com/Advanced-OpenGL/Stencil-testing). I think this technique can be translated to other APIs like DirectX or Vulkan. However, it is a bit more complicated than the answer of username_2 and probably too much for your use case.  

---

## 1 answers

### Answer by username_2 on 2021-03-27. Score: 1 | Accepted answer

Draw it twice, first time at full size and the color you want for the outline, draw it filled. The second time you draw it scaled down in both the x and y directions. The second time you draw it the color is the same as the background color, and draw it filled again. What will be left is the outline. Is this what you had in mind?

Per your comment, I add more info:

Generating an array of exterior edges can be done in a few ways. The easiest one to implement (but also the slowest) is to count the number polygons that share a given edge. The exterior is all the edges which only have a single polygon using that edge. And the two vertices that make up that edge become part of the array of "lines"( an actual line can be computed from two vertices). Also, this will count "holes" as part of the exterior. For example if a building surrounds a courtyard, then the courtyard would be counted as exterior.

This can be implemented by creating an array of unique vertices, then each polygon is formed by indexing into the list. (just like indexed triangle draw lists). Finally pick a single polygon off the list, takes its first edge, and search all the other polygons for that edge.

Another method using a doubly connected edge list is given [here](https://stackoverflow.com/questions/26103138/find-the-outline-of-adjacent-polygons).

> **Comments:**
> **username_0**: That would solve it as in it would draw the outline. Although in my case (kind of an edge case I guess) I want an array of lines that together form the outline  
> **username_2**: I updated my answer per your comment.  

---

