Combine Overlapping Polygons
Description:
Task
Given two overlapping polygons, return the polygon formed by their combined outer perimeter:
square = [(0, 0), (0, 20), (20, 20), (20, 0)]
triangle = [(5, 5), (15, 30), (30, 15)]
combined = [(0, 0), (0, 20), (11, 20), (15, 30), (30, 15), (20, 11), (20, 0)]
Polygons
For this kata, a polygon is represented as a list of pairs of rational numbers corresponding to the x and y coordinates of the vertices. The coordinates are ordered to form a path around the perimeter of the polygon. For both the input polygons and your resulting polygon, the following should be true:
- Each point on the polygon must be unique
- The polygons are non self-intersecting (no line segments cross)
- There are no holes in the polygon
Note that the last point means any holes formed by the combining of two polygons should be removed, and only the outer perimeter should be returned:
Finally, polygons do not have a set starting point nor direction. This means the following two polygons are the same:
[(0, 0), (0, 1), (1, 1), (1, 0)]
[(1, 1), (0, 1), (0, 0), (1, 0)]
However, they do need to traverse the perimeter in order (either clockwise or counterclockwise), meaning the following would not be the same (nor a valid polygon):
[(0, 0), (1, 1), (1, 0), (0, 1)]
Notes
To simplify this task, the following are guaranteed about all test cases:
- The two polygons will always overlap
- The two polygons will not share any points
- A point on one polygon will not be on the edge of the other polygon
- All input polygons will have fewer than 40 points
Similar Kata:
Stats:
Created | Jul 19, 2024 |
Published | Jul 21, 2024 |
Warriors Trained | 22 |
Total Skips | 0 |
Total Code Submissions | 81 |
Total Times Completed | 4 |
Python Completions | 4 |
Total Stars | 1 |
% of votes with a positive feedback rating | 100% of 1 |
Total "Very Satisfied" Votes | 1 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 1 |
Average Assessed Rank | 2 kyu |
Highest Assessed Rank | 2 kyu |
Lowest Assessed Rank | 2 kyu |