Jamers Posted November 23, 2017 Report Share Posted November 23, 2017 由于系统没字体,所以没使用中文的title # -*- coding: UTF-8 -*- import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties x = [[0], [1], [2]] y = [[0], [1], [2]] if ((x[0][0] == x[1][0] and x[0][0] == x[2][0]) or (y[0][0] == y[1][0] and y[0][0] == y[2][0]) or ((x[0][0]-x[1][0])/(y[0][0]-y[1][0]) == (x[0][0]-x[2][0])/(y[0][0]-y[2][0]))): online = True else: online = False #title = u'三点是否在一条直线上?:'+str(online) title = 'Is the three point in a straight line? '+str(online) plt.figure() plt.title(title) plt.xlabel('x') plt.ylabel('y') plt.axis([-2, 10, -2, 10]) plt.grid(True) plt.plot(x, y, 'k.') plt.plot(x, y, 'g-') plt.show() Link to comment Share on other sites More sharing options...
Jamers Posted November 23, 2017 Author Report Share Posted November 23, 2017 数学算法原理: 三点一线判定: 1. 三个点x轴或y轴一致,True 2. 任意两条线的斜率一致,True, (x1-x2)/(y1-y2) == (x1-x3)/(y1-y3) Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now