如何用python定義壹個函數來連接兩個點?
#導入math包import math#定義點的函數class Point: x = 0 y = 0 z = 0 def __init__(self, x, y, z): self.x = x self.y = y self.z = z def getx(self): return self.x def gety(self): return self.y def getz(self): return self.z #定義距離函數class Getlen: def __init__(self, p1, p2): self.x = p1.getx() - p2.getx() self.y = p1.gety() - p2.gety() self.z = p1.getz() - p2.getz() self.len = math.sqrt((self.x)**2 + (self.y)**2 + (self.z)**2) def getlen(self): print("兩點間的距離為:" , self.len) p1 = Point(0,0,0)p2 = Point(1,1,1)g = Getlen(p1,p2)