Method to return the equation of a straight line given two points

后端 未结 5 974
清歌不尽
清歌不尽 2020-12-29 06:17

I have a class Point, consisting of a point with x and y coordinates, and I have to write a method that computes and returns the equation of a straight line joi

5条回答
  •  伪装坚强ぢ
    2020-12-29 06:32

    class Line(object):
    
        def __init__(self,coor1,coor2):
            self.coor1 = coor1
            self.coor2 = coor2
    
    
        def distance(self):
            x1,y1 = self.coor1
            x2,y2 = self.coor2
            return ((x2-x1)**2+(y2-y1)**2)**0.5    
    
        def slope(self):
            x1,x2 = self.coor1
            y1,y2 = self.coor2
            return (float(y2-y1))/(x2-x1)
    

提交回复
热议问题