[파이썬] 두 점사이의 거리 구하기 코드
# 피타고라스 정리를 이용한, 두 점 사이의 거리 구하기 코드 2차원 공간 import math def pointDist(x1,y1,x2,y2): class Point2D: def __init__(self,x,y): self.x=x self.y=y p1=Point2D(x=x1,y=y1) p2=Point2D(x=x2,y=y2) print("p1:({},{})".format(p1.x, p1.y)) print("p2:({},{})".format(p2.x, p2.y)) dist=math.sqrt(pow(p2.x-p1.x,2)+pow(p2.y-p1.y,2)) print(dist) pointDist(30,20,50,40) >> p1:(30,20) >> p2:(50,40) >> 28.284271247461902 3차..
2020.03.28