python根据点计算直线方程
# 根据已知两点坐标,求过这两点的直线解析方程: a*x+b*y+c = 0(a >= 0)def getLinearEquation(p1x, p1y, p2x, p2y):sign = 1a = p2y - p1yif a < 0:sign = -1a = sign * ab = sign * (p1x - p2x)c = sign * (p1y * p2x - p1x * p2y
·
# 根据已知两点坐标,求过这两点的直线解析方程: a*x+b*y+c = 0 (a >= 0)
def getLinearEquation(p1x, p1y, p2x, p2y):
sign = 1
a = p2y - p1y
if a < 0:
sign = -1
a = sign * a
b = sign * (p1x - p2x)
c = sign * (p1y * p2x - p1x * p2y)
return [a, b, c]
# 根据直线的起点与终点计算出平行距离D的平行线的方程
def getLinearEquation(p1x, p1y, p2x, p2y, distance):
"""
:param p1x: 起点X
:param p1y: 起点Y
:param p2x: 终点X
:param p2y: 终点Y
:param distance: 平距
:param left_right: 向左还是向右
"""
e = getLinearEquation(p1x, p1y, p2x, p2y)
f = distance * math.sqrt(e.a * e.a + e.b * e.b)
m1 = e.c + f
m2 = e.c - f
# result = 值1 if 条件 else 值2
c2 = m1 if p2y - p1y < 0 else m2
return [e.a, e.b, c2]
更多推荐
已为社区贡献1条内容
所有评论(0)