Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point:
- def __init__(self, x, y, index):
- self.x = x
- self.y = y
- self.index = index
- def distance(self, point):
- return ((self.x - point.x)**2 + (self.y - point.y)**2)**0.5
- def __repr__(self):
- return "Point P" + str(self.index) + "(" + str(self.x) + ", " + str(self.y) + ")"
- def orientation(p1, p2, p3):
- return (p2.y - p1.y)*(p3.x - p2.x) - (p3.y - p2.y)*(p2.x - p1.x)
- def check_convex_quadrilateral(points):
- negative_angle_found = False
- positive_angle_found = False
- p1 = points[-2]
- p2 = points[-1]
- for i in range(len(points)):
- new_point = points[i]
- if orientation(p1, p2, new_point) > 0:
- positive_angle_found = True
- else:
- negative_angle_found = True
- p1 = p2
- p2 = new_point
- if positive_angle_found == negative_angle_found:
- return False
- return True
- def isOnCircle(point, r):
- # Compare radius of circle with distance of its center from given point
- if (point.x - r.x)**2 + (point.y - r.y)**2 == 0:
- print("On the circle")
- return True
- else:
- point("Isn't on circle")
- return False
- def position(point, r):
- if point.x**2 + point.y**2 - r == 0:
- print("On circle")
- elif point.x**2 + point.y**2 - r > 0:
- print("Outside")
- else:
- print("Inside")
- #Check if a polygon is convex -- complexity: O(n)
- def main():
- points = []
- count = 0
- with open("points.txt") as fin:
- for line in fin:
- input = []
- input.append([int(x) for x in line.split()])
- points.append(Point(input[0][0], input[0][1], count))
- count = count + 1
- fin.close()
- #Part I: Check if a quadrilateral is convex:
- if check_convex_quadrilateral(points) == True:
- print("The quadrilateral is convex")
- #Part II: Position of A4 for the triangle circumscribed about a circle
- else:
- print("The quadrilateral is not convex")
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement