Hello everyone, I’m trying to group parallel lines together to create walls. My problem is that, as shown on the screen, I used Springs.Geometry.GroupByDistance, and even though I set a margin, some lines are still being placed in the same group even though they don’t belong to the same wall. Any help would be appreciated. Thank you.
Hi @hayet.sassi2 ,
I am assuming that you now first made groups of parallel wall lines, from 0-180° (or maybe in steps of 5°) and then group using a certain tolerance.
Instead I’d suggest the following order:
- Instead of grouping by a given distance, extend/ buffer the current wall lines in the direction of the wall on both sides, using the same distance that you use now.
- Then use the group by distance node, using a very tiny distance (0.01) to only find overlaps, to find those that actually overlap.
Hello, thank you for your response. Could you please elaborate on the first instruction? I’m not sure I understand
There are nodes like Curve.Extend, Curve.ExtendEnd and Curve.ExtendStart which you can use to extend the curves in the direction of their vector.
Maybe this illustration helps, the red are you lines now, and the green ones are the extended ones. Then using those green, extended ones, you can check which intersect. Which in my example, only the top 2 do, and the bottom 2 don’t.
(I might have misunderstood your current input though)
Hi,
You can try grouping the parallel lines by distance from the midpoint of the lines.
Here’s the principle.
midPointonCurveA.DistanceTo(CurveB) < minDistance
Hi
There are actually a few ways to do this, I use Shapely for this type of geometric analysis.
Here’s a different solution:
With Shapely.TouchesByDistance, we can analyse the relationships between geometries using “Margin”.
Shapely.Touches : It checks whether there is any boundary contact between two geometries. In this way, we can see which geometry is in contact with the geometry I am querying
Hello, and thank you all for your responses. I realize now that I wasn’t very clear in explaining my problem.
I’ve added a screenshot to help illustrate it. I’m working with a DWG file and trying to create walls using parallel lines. However, my drawing contains lines with various thicknesses. To manage this, I set the margin for parallel lines to 0.4.
The issue is that, as shown in the screenshot, Dynamo groups four lines together because the distance between them is less than 0.4.
Hi,
Hmm… K-means might be a good solution.
Using K-means, you can perform analysis directly based on the spatial (space) positions of the data without relying on a fixed value for wall thickness. This makes it possible to group similar geometries very quickly.
# Copyright(c) 2023, Durmus Bayryam
import sys
import clrimport numpy as np
from sklearn.cluster import KMeansdata = IN[0]
n_clusters = IN[1]#Processing
X_train = np.array(data)
#Model Fit
model = KMeans(n_clusters=n_clusters, random_state=42)
model.fit(X_train)#Predict
labels = model.predict(X_train)
OUT = labels








