Group curves if their direction is similar (with tolerance)

Hi everyone,

I would like to simplify a perimeter curve, which now consists of many Lines, by grouping the Lines if they have a similar direction. For example, if the angle between two lines is less than 15 degrees.

I have tried several possibilities, but each time it was not the right solution and/or the lists became very confusing (one of my attempts is attached in the dyn-file).
Some pointers in the right direction would be great!



I have put the start and end points of some test lines in Excel, so that you do not have to run the other .dyn-file including all the files (Revit, etc.) that go with it.

Start- and Endpoints.xlsx (8.7 KB)
Group Similar Direction Test.dyn (30.0 KB)

Should be as straight forward as getting the vector of each line, converting that to an angle, and then rounding the angles to 15 degree increments.

Yeah I thought about that too, but let’s say the Angle of Line “A” is 20 degrees, this would then get rounded down to 15 degrees and Line “B” with 28 degrees would get rounded to 30 degrees. So they wouldn’t get put together correctly even though their difference is only 8 degrees.

(Assuming you mean 0-15-30-45-etc.)

True, but that’s just how rounding works. There has to be a “hard break” somewhere. On the flip side, if you had 10 lines all evenly spaced 5 degrees from each other you wouldn’t want them all to be considered the same direction. Even though the difference between any two adjacent lines is only 5 degrees, the set as a whole spans 45 degrees.

If you need to be more concise, you might look at the standard deviation between adjacent lines and try to find the “best” angles to round to based on your actual set of values, rather than prespecified increments. You’d essentially have to use a clustering algorithm, but that could be overkill for what you need.

How would one go about rounding values to a set amount of integers?

I’m not sure what you mean by that exactly. A set amount (value) would be 15 degree increments. But if you mean a set number of values, you’d have to divide your range by the number of values you want and then round to those values.

Keep in mind 15 degrees is pretty small for simplifying a curve (depending on how much you want it simplified). In this example, 15 degrees wouldn’t actually reduce the number of curves.

Of course! So simple but I just couldn’t figure it out! Will check it later today/ tomorrow! Thanks Nick :slight_smile:

Hi Nick,

I checked out your method, and unfortunately does it not work (in this state) for my perimeter. This is because my perimeter has parts which are (almost) parallel but not immediately following in the “main” list.

I’ll try to figure something out to filter out these errors.