Hello I have question to find the shortest length of line

I random list of points then find the distance btw random points and divide points on boundary rectangle what I need is the shortest line of each random-points. Thank you

Hi, I’m not sure if I understand the question but every line created in rhino, inherently has their length property. You can find all the info on line here. So there are number of ways to find the shortest line on your script. One option is to create a new for loop outside of your last for loop. Loop through each line and checking the length of it. Which might look something like this:

smallestLength = 999999999 // or some obscurely high value
for line in alllines:
    if line.Length < smallestLength:
        smallestLength = lineLength
        smallestLine = line

keep in mind this may not be the most accurate syntax.
Or you can already do this logic while creating the lines. I think this would be the fastest. You can even check the distance between the points without creating the lines, if you don’t need all the lines.
Or you can also sort the list based on the line’s length and take the first line.

Hope this helps, good luck

Hi,

you could compose a list of all distances and destinations and sort it by closest distance
( pseudo code):

dist_dests = []
for dest_point in destination_points:
   distance = get_distance(my_point,dest_point)
   dist_dests.append([distance,dest_point])
dist_dests.sort()
closest_destinaton = dist_dests[0][1]

Does that make sense?