-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise16_2.py
More file actions
38 lines (28 loc) · 929 Bytes
/
Exercise16_2.py
File metadata and controls
38 lines (28 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import math
class Point:
""" Point class for representing and manipulating x,y coordinates. """
def __init__(self, initX, initY):
""" Create a new point at the given coordinates. """
self.x = initX
self.y = initY
def getX(self):
return self.x
def getY(self):
return self.y
def distanceFromOrigin(self):
return ((self.x ** 2) + (self.y ** 2)) ** 0.5
def distanceFromPoint(self,newp):
dx = (newp.getX() - self.x)
dy = (newp.getY() - self.y)
return math.sqrt(dy**2 + dx**2)
def reflect_x(self,p):
#return "y axis = " - p.y
return "x=" + str(p.x) + ", y=" + str(- p.y)
def distance(point1, point2):
xdiff = point2.getX() - point1.getX()
ydiff = point2.getY() - point1.getY()
dist = math.sqrt(xdiff**2 + ydiff**2)
return dist
p = Point(4, 3)
q = Point(0, 0)
print(p.reflect_x(p))