20
Task
Given the x,y coordinates (coordinates are guaranteed to be integers) of the vertices of two simple polygons in clockwise or anti-clockwise order. Output a Truthy value if both the polygons are similar otherwise a Falsy value
A simple polygon is a polygon that does not intersect itself and has no holes. That is, it is a flat shape consisting of straight, non-intersecting line segments or "sides" that are joined pairwise to form a single closed path. If the sides intersect then the polygon is not simple. Two edges meeting at a corner are required to form a an angle that is not not straight (180°)
Two polygons are similar if either polygon can be rescaled, repositioned, and reflected, so as to coincide precisely with the other polygon.
Testcases
Input
[(0, 0), (1, 0), (1, 1), (0, 1)]
[(-1, 0), (2, 1), (1, 4), (-2, 3)]
Output
Truthy
Input
[(2, 3), (0, 0), (4, 0)]
[(-3, 0), (-2, 2), (0, 1), (1, -1), (-1, -2), (-2, -2)]
Output
Falsy
Input
[(1, 4), (1, 3), (0, 2), (1, 1), (-3, 2)]
[(2, 0), (2, -1), (3, -1), (4, -2), (-2, -2)]
Output
Falsy
Input
[(-1, 0), (2, 1), (1, 4), (-2, 3)]
[(1, 4), (2, 1), (-1, 0), (-2, 3)]
Output
Truthy
Input
[(-2, 0), (-1, 1), (0, 1), (1, 3), (1, 0)]
[(5, 4), (4, 2), (3, 2), (2, 1), (5, 1)]
Output
Truthy
Input
[(2, 13), (4, 8), (2, 3), (0, 8)]
[(0, 0), (5, 0), (8, 4), (3, 4)]
Output
Falsy
Input
[(-1, 0), (-5, 3), (-5, 9), (-1, 6)]
[(0, 0), (5, 0), (8, 4), (3, 4)]
Output
Falsy
Input
[(0, 0), (1, 2), (1, 0)]
[(2, 0), (2, 2), (3, 0)]
Output
Truthy
3This needs way more falsy test cases! For starters: non-similar rhombi (defeats submissions that only check side lengths); non-similar rectangles (defeats submissions that only check angles). Also, I'd suggest cutting down on the diagrams: one or two are enough to get the idea, beyond that I'd rather have all the test data in a convenient text format. – Grimmy – 2020-02-13T17:44:33.593
1@Grimmy, thanks for the suggestions working on more testcases. – Mukundan – 2020-02-13T17:52:02.153
1Ok @Mukundan and what about the fact that the tests might have different lengths? – RGS – 2020-02-13T19:15:06.003
1Are all vertices of each polygon guaranteed to be different? – Luis Mendo – 2020-02-13T22:39:22.190
1Is the penultimate test case really falsy? – Arnauld – 2020-02-13T22:58:19.360
1In the interests of being self-contained, the definition of "similar" should be included in the spec. – Shaggy – 2020-02-13T23:41:55.283
@Arnauld, Thanks for pointing that out fixed the sixth testcase – Mukundan – 2020-02-14T02:46:27.320
@LuisMendo All vertices of each polygon are guaranteed to be different – Mukundan – 2020-02-14T02:48:41.120
1@RGS No, I don't plan on changing the question to be for only polygons with same number of vertices – Mukundan – 2020-02-14T02:51:44.967
1
Related: Similar triangles
– xnor – 2020-02-14T09:10:36.840The pictures you have drawn are great. Are you sure you don't want to include them in the question? You just need to lay them out so they don't use too much space. – Anush – 2020-02-16T09:47:06.293