shapelib/core.py
def perpendicular_at(line, point, length):
    """
    line: a linestring
    point: a point within the line at which to search for a perpendicular line
    length: length of the line
    """
    point = asPoint(point)
    E = 1e-8
    if line.intersects(point):
        refpoint = point
    else:
        r = 16
        while True:
            refpoint = point.buffer(line.distance(point)+E, resolution=r).exterior.intersection(line)
            if not refpoint.is_empty:
                break
            else:
                r = r * 2
        assert not refpoint.is_empty
    a = line_angle_at(line, refpoint)
    a2 = a + pi/2
    p2 = Point(point.x, point.y + length*0.5)
    p3 = rotate(p2, -math.degrees(a2), origin=point)
    p4 = rotate(p2, (180 - math.degrees(a2)), origin=point)
    l = linestr(p3, p4)
    return l

    line: a linestring
    point: a point within the line at which to search for a perpendicular line
    length: length of the line
    
a linestring
point: a point within the line at which to search for a perpendicular line
length: length of the line
a linestring point : a point within the line at which to search for a perpendicular line length : length of the line
def perpendicular_at(line, point, length):
    point = asPoint(point)
    E = 1e-8
    if line.intersects(point):
        refpoint = point
    else:
        r = 16
        while True:
            refpoint = point.buffer(line.distance(point)+E, resolution=r).exterior.intersection(line)
            if not refpoint.is_empty:
                break
            else:
                r = r * 2
        assert not refpoint.is_empty
    a = line_angle_at(line, refpoint)
    a2 = a + pi/2
    p2 = Point(point.x, point.y + length*0.5)
    p3 = rotate(p2, -math.degrees(a2), origin=point)
    p4 = rotate(p2, (180 - math.degrees(a2)), origin=point)
    l = linestr(p3, p4)
    return l
def perpendicular_at ( line , point , length ) : point = asPoint ( point ) E = 1e-8 if line . intersects ( point ) : refpoint = point else : r = 16 while True : refpoint = point . buffer ( line . distance ( point ) + E , resolution = r ) . exterior . intersection ( line ) if not refpoint . is_empty : break else : r = r * 2 assert not refpoint . is_empty a = line_angle_at ( line , refpoint ) a2 = a + pi / 2 p2 = Point ( point . x , point . y + length * 0.5 ) p3 = rotate ( p2 , - math . degrees ( a2 ) , origin = point ) p4 = rotate ( p2 , ( 180 - math . degrees ( a2 ) ) , origin = point ) l = linestr ( p3 , p4 ) return l
line: a linestring
point: a point within the line at which to search for a perpendicular line
length: length of the line
line : a linestring point : a point within the line at which to search for a perpendicular line length : length of the line
"""
    line: a linestring
    point: a point within the line at which to search for a perpendicular line
    length: length of the line
    """
line
point
length