Hi,

can somone explain why the counter in python give me a wrong result?

I try to find all identical curve endpoints and inserted ones , grasshopper with sets gives me the correct result but counter hm…?

Hi,

can somone explain why the counter in python give me a wrong result?

I try to find all identical curve endpoints and inserted ones , grasshopper with sets gives me the correct result but counter hm…?

if i use distance it work.

```
for i in y:
r = []
for j in P:
if rh.Geometry.Point3d.DistanceToSquared(i,j) < 0.1:
r.append(j)
print len(r)
```

Hi Florian,

Looks like a floating point equality thing - the points you are creating may differ in coordinates by some tiny fraction.

Checking the distance with a tolerance as per your second post is the right way to do this.

-Graham

1 Like

Hi Florian,

I’m not sure if I correctly understand, what you’re trying to achieve, but here’s a script of mine that **sorts lines by connections to points**. It **only works with lines**, but that poses no problem with your example file!

It also **shatters lines** that are intersected by points, at parameters other than their end points.

```
import Rhino.Geometry as rg
from ghpythonlib import treehelpers
def split_line(line, params):
"""Splits a line at a series of specified parameters.
Args:
line (Rhino.Geometry.Line): A line to trim.
params (list): A list of parameters, where each parameter
must be within the line domain from 0.0 to 1.0.
Returns:
The new line segments.
"""
if 0.0 not in params:
params.append(0.0)
if 1.0 not in params:
params.append(1.0)
params = sorted(list(set(params)))
line_segs = []
for i in xrange(len(params)-1):
curr_pt = line.PointAt(params[i])
next_pt = line.PointAt(params[i+1])
if curr_pt.DistanceTo(next_pt) > 0.01:
line_segs.append(rg.Line(curr_pt, next_pt))
return line_segs
# Shatter the lines that intersect points other than their end points
shattered_lines = []
for i in xrange(len(Lines)):
params = [] # parameters to split the line at
for j in xrange(len(Points)):
if Points[j].DistanceTo(Lines[i].From) < 0.01 or \
Points[j].DistanceTo(Lines[i].To) < 0.01:
# Point equals one of the line end points
continue
else:
closest_t = Lines[i].ClosestParameter(Points[j])
closest_pt = Lines[i].PointAt(closest_t)
if Points[j].DistanceTo(closest_pt) < 0.01:
# Point intersects the line
params.append(closest_t)
if len(params) > 0:
# Shatter the line into segments
segments = split_line(Lines[i], params)
shattered_lines.extend(segments)
else:
shattered_lines.append(Lines[i])
# Get the indices of lines connected to each point
connected = []
for i in xrange(len(Points)):
conns = []
for j in xrange(len(shattered_lines)):
if Points[i].DistanceTo(shattered_lines[j].From) < 0.01 or \
Points[i].DistanceTo(shattered_lines[j].To) < 0.01:
# Point equals one of the line end points
conns.append(j)
connected.append(conns)
# Get the lines connected to each point
conn_lines = [[shattered_lines[i] for i in c] for c in connected]
# Outputs
a = treehelpers.list_to_tree(conn_lines)
```

The script outputs a **tree of lines**. Each tree branch corresponds to one of the points, in the exact same order as the input points, and includes all lines connected by one of their end points.

connected_lines.gh (17.2 KB)

Many thanks for your script.

The goal is to fix this construction at the ceiling.

The points are the suspension points and i try to write a script to calculate the weight on each suspension point.