【python】计算点到直线的距离
1. 直线采用两个端点的xy坐标表达
import numpy as np
def get_distance_point2line(point, line):
"""
Args:
point: [x0, y0]
line: [x1, y1, x2, y2]
"""
line_point1, line_point2 = np.array(line[0:2]), np.array(line[2:])
vec1 = line_point1 - point
vec2 = line_point2 - point
distance = np.abs(np.cross(vec1, vec2)) / np.linalg.norm(line_point1 - line_point2)
return distance
point =
共有 0 条评论