import math
class CPoint:
def __init__(self,x,y):
self.x=x
self.y=y
def point_distance(self,p):
return math.sqrt(math.pow(p.x-self.x,2)+math.pow(p.y-self.y,2))
def area(p1,p2,p3):
a=p1.point_distance(p2)
b=p2.point_distance(p3)
c=p1.point_distance(p3)
s=(a+b+c)/2
return math.sqrt(s*(s-a)*(s-b)*(s-c))
import point
if __name__ == "__main__":
p1=point.CPoint(5,10)
p2=point.CPoint(1,67)
p3=point.CPoint(50,-25)
print(point.CPoint.area(p1,p2,p3))
输出:1212.500000000002
如果类内函数的参数有self,那么调用的时候就要用实例对象来调用这个函数。