# ShowPointClass.py from copy import copy,deepcopy from math import sqrt from random import uniform as randu class Point: """ Attributes: x: float, the x-coordinate of a point y: float, the y-coordinate of a point """ def __init__(self,x,y): """ Creates a point. PreC: x and y are floats """ self.x = x self.y = y def __str__(self): """ Pretty prints a point object. To apply this function to a point P, write print P """ return '(%6.3f,%6.3f)' %(self.x,self.y) def MidPoint(P1,P2): """ Returns a point that is the midpoint of a line segment that connects P1 and P2. PreC: P1 and P2 are points. """ xm = (P1.x+P2.x)/2.0 ym = (P1.y+P2.y)/2.0 Q = Point(xm,ym) return Q def Dist(P1,P2): """ Returns a float that is the distance from P1 to P2. PreC: P1 and P2 are points """ d = sqrt((P1.x-P2.x)**2+(P1.y-P2.y)**2) return d def RandomPoint(L,R): """ Returns a point that is randomly chosen randomly from the square L<=x<=R, L<=y<=R. PreC: L and R are floats with L