Created
April 20, 2020 20:55
-
-
Save mlubej/1755e0620be64086597a0903b146f16c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_unique_orientations(poly): | |
""" | |
Out of all possible rotations and flips, take into account the polygon symmetry and | |
obtain the unique polygon orientations. | |
:param poly: input polygon | |
:return: array of unique settings of (rotation, flip) | |
""" | |
cx, cy = poly.centroid.x, poly.centroid.y | |
pts = np.array(poly.checkers)[:, :-1] | |
checkers = np.array(poly.checkers)[:, -1] | |
pts = pts[checkers == 1] | |
poly = poly.difference(MultiPoint(pts + 0.5).buffer(0.2)) | |
rots = [0, 90, 180, 270] | |
flips = [1, -1] | |
iterables = [rots, flips] | |
settings = np.array(list(itertools.product(*iterables))) | |
unique_polys = [] | |
unique_settings = [] | |
for rot, flip in settings: | |
p = poly | |
p = rotate(p, rot, origin=[cx, cy]) | |
p = scale(p, flip, origin=[cx, cy, 0]) | |
if np.any([p.difference(u).area < 1e-5 for u in unique_polys]): | |
continue | |
unique_polys.append(p) | |
unique_settings.append([rot, flip]) | |
return unique_settings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment