Functions and Recursions – Geometry – Problem #3
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
A polygon is said to be simple if its non-adjacent sides do not intersect each other. Write a C program to find out whether an input polygon is simple. It should have the following input/output behavior: The program first takes in the number of vertices from the user. Then it takes in n integer points (i.e., points with integer coordinates) as vertices from the user. The user is assumed to enter these points either in clockwise or in anticlockwise order. In other words, the sides of the polygon connect consecutive vertices in the input sequence (and the last and the first vertices). The program outputs whether or not the polygon is simple. If the polygon is not simple, it also outputs the number of intersection points among the non-adjacent sides. You should write a function that takes as input the endpoints of two straight line segments and returns whether they intersect or not. Call this function from main() to determine the intersection between every two non-adjacent sides of the polygon.