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.
Thanks in advance.
i think you have to add some “clever” geometry for detecting it…
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:
Sorry I’m new I can’t upload script.
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.
Also, why didnt this work?
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.
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.
Good idea, but now struggling with dynamo logic of splitting circles…
or use geometry does intersect!
with project curve
forum anglais 29 septembre.dyn (26.8 KB)
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!
Just a FYI about the angle approach:
- Get all the curves from the polygon in order.
- Shift all indices in the list by 1, such that you can easily compare the curve against the next one.
- Measure each curve direction against the x-axis, this will result in angles.
- Do a simple subtraction, if the value is negative/ positive you know if the angle is convex or concave.
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.
room generator.dyn (223.1 KB)
another workflow using python:
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:
- Take the polycurve and explode it so you have a list of all curves
- 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.
- For the original curve list, get the tangent direction at the end
- For the shifted list get the tangent direction at the start
- Build a surface of the polycurve, and pull it’s normal
- Use a Vector.AngleAboutAxis to get the angle from the original curves end tangent vectors (#3) and the shifted curves tangent start vectors about the normal.
- Values over 180 are convex, less than 180 concave, and if 180 it’s colinear (and likely you want to combine the angles)
Actually… played around with this and got an even better (and faster) solution.
Starting with the polygon:
- Explode the polygon
- For each curve, find a point just before it’s start (
- Check if that point is inside the polygon (
- Get the points of the polygon, and filter them by the containment test results.
- If inside, the corner is concave. otherwise they are convex.