Skip to content

Instantly share code, notes, and snippets.

@akirap3
Created December 31, 2020 06:34
Show Gist options
  • Save akirap3/9b81f40528c28f63d5af23145bc7916b to your computer and use it in GitHub Desktop.
Save akirap3/9b81f40528c28f63d5af23145bc7916b to your computer and use it in GitHub Desktop.
import math

class Point:
    def __init__(self, x=0.0, y=0.0):
        self.__x = x
        self.__y = y
    
    def getx(self):
        return self.__x
    
    def gety(self):
        return self.__y
        
    def distance_from_xy(self, x, y):
        return math.hypot((x - self.getx()),(y - self.gety()))
        
    def distance_from_point(self, point):
        return math.hypot((point.getx()-self.getx()),(point.gety()-self.gety()))

point1 = Point(0,0)
point2 = Point(1,1)
print(point1.distance_from_point(point2))
print(point2.distance_from_xy(2,0))
        
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment