---
title: "AI 给出两个点画一条直线"
author: "e_e"
date: "2023-11-30T15:58:51Z"
tags: []
categories: ["编程语言"]
slug: "ai"
draft: false
lastmod: "2023-11-30T15:58:51Z"
id: 2539606
url: "https://e-e.iteye.com/blog/2539606"
---

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)