Problem 194. Clockwise or Counterclockwise
Solution Stats
Problem Comments
-
3 Comments
added more samples to the test
Hello, Alfonso Nieto-Castanon. This is a very nice problem. It was interesting to see the variety of approaches used to solve it. It was also interesting to notice a few submissions failed your added test cases from circa Dec 2017. Do you allow for self-intersecting polygons, as per https://en.wikipedia.org/wiki/Polygon ?
I suspect a common solution tactic will fail badly when faced with self-intersecting polygons. —DIV
...On second thought, maybe there's no consistent definition of CW/CCW for self-intersecting polygons, such as figure-eight or bow-tie ("cross-quadrilateral") shapes.
Solution Comments
-
1 Comment
the last test
-
1 Comment
I don't understand why the vector sizes of x and y for the last test case are both 100x15. The problem strictly says that the points are 2-dimensional. Can someone explain this?
-
1 Comment
I like the readability of this submission. However the logic of the if statement is curious to me: it seems that after setting tf to false, tf can be reset back to true. Would it be more robust to either (i) initialise tf before your loop, or (ii) include a "break" command?
-
1 Comment
Simply beautiful!
-
1 Comment
Didn't realize ispolycw was in the Mapping Toolbox, and not Cody friendly.
-
2 Comments
This method (as well as several others) would fail in a more extensive test suite; for example, when x = [1,1,2] and y = [2,1,1]; or when x = [-2,-2,-4,-4] and y = [1,3,1,-1]; or when x = [-1,-1,3] and y = [-3,1,1].
@yurenchu, Thanks for pointing this out, I have added a few more test cases now
Problem Recent Solvers104
Suggested Problems
-
80676 Solvers
-
4796 Solvers
-
Back to basics 3 - Temp Directory
358 Solvers
-
Convert a vector into a number
575 Solvers
-
Given a square and a circle, please decide whether the square covers more area.
636 Solvers
More from this Author38
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!