-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSegmentData.py
More file actions
36 lines (29 loc) · 943 Bytes
/
SegmentData.py
File metadata and controls
36 lines (29 loc) · 943 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
"""
This program defines the classes for
line segments in a 2D geometric space
Author: Ajinkya Dhaigude (ad8454@rit.edu)
"""
class Point:
def __init__(self, name, x, y):
self.name = name
self.x = x
self.y = y
self.seen = False
class Segment:
def __init__(self, name, p, q):
self.name = name
self.leftPoint = p
self.rightPoint = q
if q.x < p.x:
self.leftPoint = q
self.rightPoint = p
self.slope = (self.rightPoint.y - self.leftPoint.y) / (self.rightPoint.x - self.leftPoint.x)
self.const = self.leftPoint.y - (self.slope * self.leftPoint.x)
def isPointAbove(self, point):
if point.y > (self.slope * point.x) + self.const:
return True
return False
def getY(self, x):
if self.leftPoint.x <= x <= self.rightPoint.x:
return (self.slope * x) + self.const
return None