Jump to content
新域网络技术论坛

Python中的简单示例代码(三点是否在一条直线上)


Jamers
 Share

Recommended Posts

由于系统没字体,所以没使用中文的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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...