# Determine if polygon corner is convex or concave

**URL:** <https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595>\
**Category:** Geometry\
**Tags:** dynamo\
**Created:** [September 29, 2022, 7:33am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595 "2022-09-29T07:33:09Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![mutalisk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mutalisk/32/147599_2.png) [@mutalisk](https://forum.dynamobim.com/u/mutalisk)\
**Post date:** [September 29, 2022, 7:33am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/1 "2022-09-29T07:33:09Z")

</div>

Hello Dynamo users.  
I’m stuck on my project on determining witch polygon corner is convex or concave. Tried already measuring vector angles, calculating point distances, but there is always an exception for that approach.  
Did anyone faced similar problem. Example in screenshot. One good thing is, angle is always 90.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/a/0a6e400bed57379700d8ff31f51a7c35ccbd913e.png)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 29, 2022, 8:13am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/2 "2022-09-29T08:13:46Z")

</div>

@mutalisk ,hi

i think you have to add some “clever” geometry for detecting it…

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/5/f5d3ecccd7f6d98cdc392bb7dbb96071bef1015b.png)  
 ![ConvexConcav](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/a/1ab8a1f43d94210d684f10bd1a00a9847e8a42ad.png)  
KR  
Andreas  
[ConvexConcav\_V01.dyn](https://forum.dynamobim.com/uploads/short-url/gurqLxMe2pgmYKgpDohUaXPvxix.dyn) (39.6 KB)

---

<div class="post-metadata">

**Author:** ![mutalisk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mutalisk/32/147599_2.png) [@mutalisk](https://forum.dynamobim.com/u/mutalisk)\
**Post date:** [September 29, 2022, 8:22am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/3 "2022-09-29T08:22:18Z")

</div>

Thanks for answer.  
Yes I tried like it. But the polygon outline is random. It can be more complicated and have “bays” then the result would be not true. I mean using middle point will not always work. Example:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/d/cd8f7479184ced3459e715abbf18d15ff132cc2a.png)

Sorry I’m new I can’t upload script.

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [September 29, 2022, 9:31am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/5 "2022-09-29T09:31:25Z")

</div>

Hi @mutalisk ,

Woulnd’t all corners where the line goes to the left always be concave (and vice versa)?  
Assuming we are looking at a clockwise polycurve. Otherwise its just the other way around.

> [@mutalisk](#):
>
> Tried already measuring vector angles

Also, why didnt this work?

---

<div class="post-metadata">

**Author:** ![mutalisk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mutalisk/32/147599_2.png) [@mutalisk](https://forum.dynamobim.com/u/mutalisk)\
**Post date:** [September 29, 2022, 9:39am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/6 "2022-09-29T09:39:17Z")

</div>

Left and right is a good idea, but no idea how to implement it, how to check if it left or right turn? . With vectors maybe it didin’t work because I’m not master of it. It was hard to determine witch angle is measured, exterior or interior angle, and it can be 90 and be convex or concave, or I get it wrong.

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [September 29, 2022, 9:49am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/7 "2022-09-29T09:49:18Z")

</div>

Hello,  
if you project a circle at each corner and you get the length of the resulting curve on the surface of the polygon  
then you compare to the lenght of 1/4 of the arc.

Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![mutalisk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mutalisk/32/147599_2.png) [@mutalisk](https://forum.dynamobim.com/u/mutalisk)\
**Post date:** [September 29, 2022, 10:07am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/8 "2022-09-29T10:07:49Z")

</div>

Good idea, but now struggling with dynamo logic of splitting circles…

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/2/72cb2d2daac4f038ee568d6cbc7cb6786adf47e4.png)

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 29, 2022, 10:12am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/9 "2022-09-29T10:12:47Z")

</div>

@mutalisk ,

or use geometry does intersect!

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/c/4c34d045ef02592b9a358461bf34aed52e9a9f0c.png)

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [September 29, 2022, 10:54am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/10 "2022-09-29T10:54:42Z")

</div>

hello

with project curve

 ![Capture d’écran 2022-09-29 125248](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/e/8ecf57853d0536710153e3b283902861ac8a5f5a.jpeg)

script:  
[forum anglais 29 septembre.dyn](https://forum.dynamobim.com/uploads/short-url/g54cAet3RL8CXCDzz3WQE0z3hLy.dyn) (26.8 KB)

cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![mutalisk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mutalisk/32/147599_2.png) [@mutalisk](https://forum.dynamobim.com/u/mutalisk)\
**Post date:** [September 29, 2022, 11:18am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/11 "2022-09-29T11:18:15Z")

</div>

Now I get it. That’s brilliant, its like containment test but with curves and splitting it in the same time thanks a lot. Worked!

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [September 29, 2022, 12:59pm UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/12 "2022-09-29T12:59:25Z")

</div>

Just a FYI about the angle approach:

1. Get all the curves from the polygon in order.
2. Shift all indices in the list by 1, such that you can easily compare the curve against the next one.
3. Measure each curve direction against the x-axis, this will result in angles.
4. Do a simple subtraction, if the value is negative/ positive you know if the angle is convex or concave.

---

<div class="post-metadata">

**Author:** ![mutalisk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mutalisk/32/147599_2.png) [@mutalisk](https://forum.dynamobim.com/u/mutalisk)\
**Post date:** [September 29, 2022, 1:55pm UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/13 "2022-09-29T13:55:39Z")

</div>

Thank you all, this is used for random room layout generator, you can set room size. This is for testing the generative design feature in Revit.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/b/dbefbae97b52b8ded0b03e0aae0c45dc369dc96a.png)

Script:  
[room generator.dyn](https://forum.dynamobim.com/uploads/short-url/81BOkfNfqjuklfNFxS8HY8bj1C7.dyn) (223.1 KB)

---

<div class="post-metadata">

**Author:** ![newshunhk](https://avatars.discourse-cdn.com/v4/letter/n/3bc359/32.png) [@newshunhk](https://forum.dynamobim.com/u/newshunhk)\
**Post date:** [September 29, 2022, 2:32pm UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/14 "2022-09-29T14:32:40Z")

</div>

another workflow using python:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/5/5535b556e57c26dac17b7443711e7721ad289143.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 1, 2022, 6:29pm UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/15 "2022-10-01T18:29:03Z")

</div>

Since you’re working with planar geometry we can simplify things a bit and remove the computational difficult geometry calculations. Assuming you start with a polycurve:

1. Take the polycurve and explode it so you have a list of all curves
2. Shift that list by 1 unit (so the second curve in the list is now first, and the first curve in the list is now last) with a List.ShiftIndices node.
3. For the original curve list, get the tangent direction at the end
4. For the shifted list get the tangent direction at the start
5. Build a surface of the polycurve, and pull it’s normal
6. Use a [Vector.AngleAboutAxis](https://dictionary.dynamobim.com/#/Geometry/Vector/Action/AngleAboutAxis) to get the angle from the original curves end tangent vectors (#3) and the shifted curves tangent start vectors about the normal.
7. Values over 180 are convex, less than 180 concave, and if 180 it’s colinear (and likely you want to combine the angles)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 2, 2022, 12:11am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/16 "2022-10-02T00:11:16Z")

</div>

Actually… played around with this and got an even better (and faster) solution.

Starting with the polygon:

1. Explode the polygon
2. For each curve, find a point just before it’s start (`Curve.PointAtParmater(crv, -0.0001)`)
3. Check if that point is inside the polygon (`Polygon.ContainmentTest(polygon,pnts)`)
4. Get the points of the polygon, and filter them by the containment test results.
5. If inside, the corner is concave. otherwise they are convex.

---

<div class="post-metadata">

**Author:** ![bayowindapo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/bayowindapo/32/184532_2.png) [@bayowindapo](https://forum.dynamobim.com/u/bayowindapo)\
**Post date:** [October 2, 2022, 6:28am UTC](https://forum.dynamobim.com/t/determine-if-polygon-corner-is-convex-or-concave/81595/17 "2022-10-02T06:28:15Z")

</div>

Awesome.
