[Python] finding nearest perpendicular point to a line

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    i am trying to find the perpendicular closest point to a line, given:

    line is given by p1 and p2:
    p1= [833974.3939975424, 10.741845010809124]
    p2= [833972.1988621169, 9.989807874318076]

    point: [833972.4500000001, 10.200000000000001]

    I used these functions:


    point1, point2 = nearest_points(shp.LineString([shp.Point(p1[0], p1[1]), shp.Point(p2[0], p2[1])]), shp.Point([point[0], point[1]]))

    # and
    line= shp.LineString([shp.Point(p1[0], p1[1]), shp.Point(p2[0], p2[1])])
    pdist= line.project(shp.Point([point[0], point[1]]))
    newpoint= line.interpolate(pdist)


    when I use shapely functions, scikit-spatial, etc. I get the nearest non-perpendicular point as given in red (projected from green): [​IMG]

    PLease, if anyone can help: I have been trying for hours to project the red point perpendicular to the line. I couldnt find a proper similar stack overflow answer.

    Continue reading...

Compartilhe esta Página