主页 > 程序语言 > 求一段Python编程语言 求设计一段Python编程语言,

求一段Python编程语言 求设计一段Python编程语言,

2021-10-15 06:36来源:m.sf1369.com作者:宇宇

回炉了一下几何,图形学用到
import math
class Point:
   def __init__(self):
       self.x=0
       self.y=0
   def input(self,pname):
       self.x=int(input(Enter the x of point {0}: .format(pname)))
       self.y=int(input(Enter the y of point {0}: .format(pname)))
a=Point()
b=Point()
c=Point()
a.input(A)
b.input(B)
c.input(C)
if a.x==b.x: #When the line is vetical to y-axis
   x=a.x
   print(Formula: x={0}.format(a.x))
else:    
   k=(b.y-a.y)/(b.x-a.x)
   y_intercept=a.y-k*a.x
   print(Formula: y={0}x+{1}.format(k,y_intercept))
distance=abs((b.y-a.y)*c.x - (b.x-a.x)*c.y + b.x*a.y +b.y*a.x) / math.sqrt((b.y-a.y)**2+(b.x-a.x)**2)

print('The distance from the point C({0},{1}) to a line[A({2},{3})-B({4},{5})] is {6}'
   .format(c.x,c.y, a.x, a.y, b.x, b.y, distance))Enter the x of point A: 0
Enter the y of point A: 5
Enter the x of point B: 5
Enter the y of point B: 5
Enter the x of point C: 5
Enter the y of point C: 0
Formula: y=0.0x+5.0
The distance from the point C(5,0) to a line[A(0,5)-B(5,5] is 5.0

相关推荐

哪些编程语言是函数式的

程序语言 2024-01-14

VB编程的函数详解

程序语言 2024-01-02

c语言扑克牌问题

程序语言 2023-12-28

iphone语言与地区有什么用?

程序语言 2023-12-19

C语言程序,怎么使用,

程序语言 2023-12-17

把word嵌入到C#程序中

程序语言 2023-11-26

HTML是不是编程语言?

程序语言 2023-11-17