`

AI 给出两个点画一条直线

    博客分类:
  • AI
阅读更多
import numpy as np
from matplotlib import pyplot as plt
import math

x1,y1 = 2,3
x2,y2 = 7,10
# p1,q1 = 4,8
# p2,q2 = 6,3

plt.plot(x1,y1,'ob')
plt.plot(x2,y2,'ob')

# plt.plot(p1,q1, 'or')
# plt.plot(p2,q2, 'or')

def get_k(x1,y1,x2,y2):
  k = (y1-y2)/(x1-x2)
  return k

def get_b(x1,y1,x2,y2):
  b = (x1*y2-x2*y1)/(x1-x2)
  return b

k1 = get_k(x1,y1,x2,y2)
b1 = get_b(x1,y1,x2,y2)
x_1 = np.arange(1,10,0.2)
y_1 = k1 *x_1 +b1
plt.plot(x_1,y_1,linewidth=0.5)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics