# Get all points contained within a line segment

**URL:** <https://forum.dynamobim.com/t/get-all-points-contained-within-a-line-segment/97036>\
**Category:** Geometry\
**Tags:** revit, python, dynamo\
**Created:** [January 11, 2024, 6:44am UTC](https://forum.dynamobim.com/t/get-all-points-contained-within-a-line-segment/97036 "2024-01-11T06:44:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dweber12](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@dweber12](https://forum.dynamobim.com/u/dweber12)\
**Post date:** [January 11, 2024, 6:44am UTC](https://forum.dynamobim.com/t/get-all-points-contained-within-a-line-segment/97036/1 "2024-01-11T06:44:15Z")

</div>

Hello dynamo wizards, I am trying to determine if there is a way to take a list of line segments and a list of points and find all locations where the points are contained in the lines. Is there a solution where this is possible? Thank you for any assistance you can provide.

---

<div class="post-metadata">

**Author:** ![gilberto.arechigaiba](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gilberto.arechigaiba/32/204980_2.png) [@gilberto.arechigaiba](https://forum.dynamobim.com/u/gilberto.arechigaiba)\
**Post date:** [January 11, 2024, 7:17am UTC](https://forum.dynamobim.com/t/get-all-points-contained-within-a-line-segment/97036/2 "2024-01-11T07:17:42Z")

</div>

Hola amigo @dweber12 buenas. is this what are you looking for??

 ![Get curves of a polycurve and points](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/d/0dffccd0e1064a5f376283086de26295d1e7b09e.jpeg)

---

<div class="post-metadata">

**Author:** ![sovitek](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sovitek/32/116237_2.png) [@sovitek](https://forum.dynamobim.com/u/sovitek)\
**Post date:** [January 11, 2024, 7:35am UTC](https://forum.dynamobim.com/t/get-all-points-contained-within-a-line-segment/97036/3 "2024-01-11T07:35:11Z")

</div>

Hi @dweber12 how about some intersection, if i understand right 😉 here is a fast example…can probably be done many ways and more elegant

 ![Skærmbillede 2024-01-11 083127](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/d/7d6b5338a54b0353c0e3f0d70ae42d18acacc65e.png)

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [January 11, 2024, 9:01pm UTC](https://forum.dynamobim.com/t/get-all-points-contained-within-a-line-segment/97036/4 "2024-01-11T21:01:22Z")

</div>

Using a distance calculation is a fast way to determine if points are on lines.

Iteration over the whole data set is costly though, so some pre-filtering to determine approximate spacial relationships would before processing would be beneficial. 😉

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/0/f0d84c0fbf9973da8f0721d57b3ae20d081b8318.png)

**Py - Group Points on Lines**

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import math
from math import sqrt

def close_point(p1, p2, p3):
    x1, y1, z1 = p1
    x2, y2, z2 = p2
    x3, y3, z3 = p3
    dx, dy, dz = x2 - x1, y2 - y1, z2 - z1
    det = dx * dx + dy * dy + dz * dz
    a = (dx * (x3 - x1) + dy * (y3 - y1) + dz * (z3 - z1)) / det
    return x1 + a * dx, y1 + a * dy, z1 + a * dz

points = IN[0]
lines = IN[1]

tolerance = 0.001

result = []

for l in lines:
    # If points occur on the line add to its group
    group = []
    line_start = [l.StartPoint.X,l.StartPoint.Y,l.StartPoint.Z]
    line_end = [l.EndPoint.X,l.EndPoint.Y,l.EndPoint.Z]
    # Iterate points
    for p in points:
        coord = [p.X,p.Y,p.Z]
        lineP = close_point(line_start,line_end,coord)
        dist = sqrt( (lineP[0] - coord[0])**2 + (lineP[1] - coord[1])**2 + (lineP[2] - coord[2])**2 )
        if dist < tolerance:
            group.append(p)
    result.append(group)
OUT = result

```
