generative modeling for Rhino
I am trying to write a simple script to remove duplicated polylines.
the polylines are closed edges of trangular surfaces. each surface has more than 2 duplicates. what i am trying to do is to find the contre of each polyline. if the centres are the same, polyline will be removed from the list.
Here is my script:
Dim i As Integer
Dim j As Integer
Dim threshold As Integer:threshold = 1
Dim cen As New Point3d
Dim pLine As New Polyline
Dim pList As New list(Of Polyline):pList = x
Dim cenT As New Point3d
Dim pLineT As New polyline
For i = 0 To x.Count - 1
pLine = x(i)
cen = pLine.CenterPoint
For j = 0 To x.Count - 1
If Not j = i Then
pLineT = x(j)
cenT = pLineT.CenterPoint
If cen.DistanceTo(cenT) <= threshold Then
A = indexList
I think I have found the problem which is: duplicated polylines are being removed more than one time. but I can't find the right syntax to correct it....
many thanks in advance!!
i think i have solved the problem by myself. In stead of removing objects from a list, now i just create a new empty list to add non-repeated objects in.
if you're removing items from a collection, you should iterate over it backwards. If you iterate forwards you have to adjust your iteration variable on every remove. There were other weird things in your code, a lot of pointless New keywords. Below is how I would write it.
Dim tolerance As Double = 1.0
'First collect all center points.
Dim c As New List(Of Point3d)
For Each polyline As Polyline in x
For i As Int32 = x.Count - 1 To 1 Step -1
For j As Int32 = 0 To i-1
If (c(i).DistanceTo(c(j)) < tolerance) Then
A = x
well..... i have to say, this is really cool. much more simplified. best solution is always simplest.
thanks a lot! really appreciate it!
using a center point tolerance is not going to work all the time. What if you have two polylines whose center points are in the same place? i.e. if they are crossing one another. You pribably want to use a boundary box inclusion test for this
hey Steve, can you be more specific about boundary box inclusion test?
It all depends on whether you want to find identical polylines, identical polylines within a tolerance x or polylines that have similar shape.
You can test all sorts of properties depending on which of the above cases you're working with:
These cases are sorted by performance, but only the last one will allow you to find similar looking polylines.
See this script which implements all of the above comparisons. I hope it opens up correctly on older versions though.
sorry for late reply, but thanks lot David! It is super helpful!
Attached is my GH definition which is a geodesic Dome solution.
What I did was to create geodesic dome from an icosahedron. once the icosahedron is created, all the vertices remain undifferentiated. If I draw polyline between each vertice and its closest two vertices, all plygons will be drawn twice.
and this is when removing duplicate polylines starts to work.