支持方法:构造函数将表示端点的一对点对象作为输入,返回线段的长度,并返回线段的坡度,如果坡度是无界的,则返回无坡度。这是到目前为止我得到的,但是我一直得到一个错误,说无法检测未定义的名称。在
import math
from Point import *
class Segment:
def __init__(self,point1, point2):
self.p1 = point1
self.p2 = point2
def length(self):
x1,x2 = self.p1.getx(),self.p2.getx()
y1,y2 = self.p1.gety(), self.p2.gety()
d = (x1**2 - x2**2) + (y1**2 - y2**2)
d = math.sqrt(d)
return d
结果如下:
p1 = Point(3,4)
p2 = Point()
s = Segment (p1, p2)
s.length()
5.0款
s.slope()
0.75
目前没有回答
相关问题 更多 >
编程相关推荐