Cody

# Problem 194. Clockwise or Counterclockwise

Solution 104839

Submitted on 29 Jun 2012 by Aurelien Queffurust
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = [-1,-1,1,1]; y = [-1,1,1,-1]; d_correct = true; assert(isequal(isSortedClockwise(x,y),d_correct))

k = 1 4 3 2 1 tf = logical 1

2   Pass
x = [-1,-1,-2,-2]; y = [-1,1,1,-1]; d_correct = false; assert(isequal(isSortedClockwise(x,y),d_correct))

k = 1 2 3 4 1 tf = logical 0

3   Pass
x = [-1,-1,-2,-2]; y = [-1,1,1,-1]; d_correct = false; assert(isequal(isSortedClockwise(x,y),d_correct))

k = 1 2 3 4 1 tf = logical 0

4   Pass
x = [-6,-7,-2,1,1,-2]; y = [4,-7,-13,-11,0,5]; d_correct = false; assert(isequal(isSortedClockwise(x,y),d_correct))

k = 1 2 3 4 5 6 1 tf = logical 0

5   Pass
x = [-59,-59,-55,-51,-50,-46,-45,-45,-39,-40,-40,-41,-46,-50,-50]; y = [-68,-33, -5,-13,-28,-30,-20,-10, -8,-23,-34,-45,-48,-51,-51]; d_correct = true; assert(isequal(isSortedClockwise(x,y),d_correct))

[Warning: Duplicate data points have been detected and removed. The Triangulation indices are defined with respect to the unique set of points in DelaunayTri.] [> In isSortedClockwise (line 2) In ScoringEngineTestPoint5 (line 4) In solutionTest (line 11)] k = 1 12 11 9 3 2 1 tf = logical 1

6   Pass
x = flip([-59,-59,-55,-51,-50,-46,-45,-45,-39,-40,-40,-41,-46,-50,-50]); y = flip([-68,-33, -5,-13,-28,-30,-20,-10, -8,-23,-34,-45,-48,-51,-51]); d_correct = false; assert(isequal(isSortedClockwise(x,y),d_correct))

[Warning: Duplicate data points have been detected and removed. The Triangulation indices are defined with respect to the unique set of points in DelaunayTri.] [> In isSortedClockwise (line 2) In ScoringEngineTestPoint6 (line 4) In solutionTest (line 13)] k = 3 4 6 12 13 14 3 tf = logical 0

7   Pass
x = [1,1,2,2]; y = [2,1,1,2]; assert(isequal(isSortedClockwise(x,y),false));

k = 1 2 3 4 1 tf = logical 0

8   Pass
x = flip([1,1,2,2]); y = flip([2,1,1,2]); assert(isequal(isSortedClockwise(x,y),true));

k = 1 4 3 2 1 tf = logical 1

9   Pass
x = [-2,-2,-4,-4]; y = [1,3,1,-1]; assert(isequal(isSortedClockwise(x,y),false));

k = 1 2 3 4 1 tf = logical 0

10   Pass
x = flip([-2,-2,-4,-4]); y = flip([1,3,1,-1]); assert(isequal(isSortedClockwise(x,y),true));

k = 1 4 3 2 1 tf = logical 1

11   Pass
r=rand(100,15); a=2*pi*rand(100,1); d=2*(rand(100,1)>.5)-1; x=r.*cos(a*ones(1,15)+d*2*pi*(0:14)/15)+randn(100,1); y=r.*sin(a*ones(1,15)+d*2*pi*(0:14)/15)+randn(100,1); assert(all(arrayfun(@(i)isequal(isSortedClockwise(x(i,:),y(i,:)),d(i)<0),1:100)))

k = 1 14 12 9 6 5 1 tf = logical 1 k = 2 14 13 10 7 6 5 4 3 2 tf = logical 1 k = 2 15 14 12 10 7 5 3 2 tf = logical 1 k = 2 15 12 9 8 6 2 tf = logical 1 k = 1 3 4 5 7 8 9 12 13 15 1 tf = logical 0 k = 3 15 14 13 12 11 9 8 5 3 tf = logical 1 k = 2 5 7 9 12 13 15 2 tf = logical 0 k = 3 4 8 12 13 15 3 tf = logical 0 k = 2 14 10 9 7 4 3 2 tf = logical 1 k = 2 3 5 6 8 10 13 14 15 2 tf = logical 0 k = 1 14 13 11 9 8 7 3 1 tf = logical 1 k = 2 5 7 8 9 10 12 14 2 tf = logical 0 k = 3 14 12 10 9 7 6 4 3 tf = logical 1 k = 3 15 14 11 10 7 4 3 tf = logical 1 k = 1 3 5 8 10 13 15 1 tf = logical 0 k = 1 14 10 8 5 1 tf = logical 1 k = 2 6 9 10 11 14 15 2 tf = logical 0 k = 1 14 11 9 6 4 1 tf = logical 1 k = 5 15 13 11 9 7 6 5 tf = logical 1 k = 3 4 5 8 9 11 12 13 3 tf = logical 0 k = 1 14 11 7 2 1 tf = logical 1 k = 4 15 12 11 10 8 7 4 tf = logical 1 k = 1 2 4 7 9 10 11 14 1 tf = logical 0 k = 1 13 10 9 8 7 5 1 tf = logical 1 k = 2 15 12 10 5 4 2 tf = logical 1 k = 1 2 4 6 10 14 15 1 tf = logical 0 k = 2 4 6 7 9 12 13 15 2 tf = logical 0 k = 1 3 4 7 9 11 14 1 tf = logical 0 k = 1 14 10 5 4 3 2 1 tf = logical 1 k = 1 13 11 8 7 5 2 1 tf = logical 1 k = 1 5 6 7 9 11 13 14 1 tf = logical 0 k = 2 14 13 12 9 8 6 4 3 2 tf = logical 1 k = 1 13 12 10 7 4 2 1 tf = logical 1 k = 1 14 13 10 8 6 3 1 tf = logical 1 k = 2 14 13 8 5 4 2 tf = logical 1 k = 1 13 11 10 9 8 6 4 1 tf = logical 1 k = 2 14 10 8 7 5 3 2 tf = logical 1 k = 4 6 7 10 11 14 15 4 tf = logical 0 k = 1 14 11 9 6 5 4 1 tf = logical 1 k = 4 5 8 9 11 14 4 tf = logical 0 k = 1 12 7 4 1 tf = logical 1 k = 2 14 12 9 7 6 5 3 2 tf = logical 1 k = 2 5 7 10 11 12 2 tf = logical 0 k = 1 2 3 5 9 10 13 1 tf = logical 0 k = 5 14 13 12 9 6 5 tf = logical 1 k = 1 2 5 8 9 11 13 1 tf = logical 0 k = 3 15 12 10 6 4 3 tf = logical 1 k = 3 14 11 10 9 8 5 4 3 tf = logical 1 k = 3 15 13 12 11 9 7 3 tf = logical 1 k = 2 3 7 9 11 13 14 2 tf = logical 0 k = 3 4 6 10 11 13 3 tf = logical 0 k = 1 2 6 8 11 13 15 1 tf = logical 0 k = 3 4 7 9 12 14 15 3 tf = logical 0 k = 3 13 11 10 8 7 6 4 3 tf = logical 1 k = 1 3 5 8 10 14 1 tf = logical 0 k = 2 15 14 11 7 5 3 2 tf = logical 1 k = 6 9 10 11 14 15 6 tf = logical 0 k = 3 15 13 10 9 7 5 3 tf = logical 1 k = 3 15 13 9 7 6 3 tf = logical 1 k = 3 4 8 11 13 14 15 3 tf = logical 0 k = 2 15 11 7 4 2 tf = logical 1 k = 1 4 5 8 10 12 15 1 tf = logical 0 k = 1 3 5 6 10 11 14 1 tf = logical 0 k = 2 13 12 9 8 6 3 2 tf = logical 1 k = 3 14 12 11 9 7 6 3 tf = logical 1 k = 2 4 7 8 10 12 15 2 tf = logical 0 k = 1 3 4 6 9 12 13 1 tf = logical 0 k = 2 5 6 7 8 12 15 2 tf = logical 0 k = 2 4 6 8 10 11 13 2 tf = logical 0 k = 1 5 8 9 13 15 1 tf = logical 0 k = 2 7 10 15 2 tf = logical 0 k = 1 3 4 5 10 13 15 1 tf = logical 0 k = 3 15 14 13 10 7 4 3 tf = logical 1 k = 1 14 13 12 7 4 3 1 tf = logical 1 k = 4 14 12 10 9 6 4 tf = logical 1 k = 1 14 11 9 8 7 5 3 1 tf = logical 1 k = 1 3 4 6 9 11 12 14 1 tf = logical 0 k = 1 15 12 7 4 1 tf = logical 1 k = 1 12 11 9 7 4 3 1 tf = logical 1 k = 3 15 14 12 11 10 6 3 tf = logical 1 k = 1 15 14 12 9 7 6 4 2 1 tf = logical 1 k = 2 14 12 9 8 7 5 3 2 tf = logical 1 k = 2 3 5 6 8 11 12 13 14 2 tf = logical 0 k = 1 12 11 8 6 5 2 1 tf = logical 1 k = 1 3 6 11 12 1 tf = logical 0 k = 1 13 12 11 10 8 7 4 3 1 tf = logical 1 k = 1 3 5 9 10 11 15 1 tf = logical 0 k = 1 15 14 13 9 6 3 1 tf = logical 1 k = 1 3 4 7 9 10 12 13 1 tf = logical 0 k = 2 14 12 9 6 4 3 2 tf = logical 1 k = 2 15 13 11 8 6 3 2 tf = logical 1 k = 3 4 8 9 13 15 3 tf = logical 0 k = 1 2 4 6 8 13 14 1 tf = logical 0 k = 1 3 5 6 7 9 11 13 1 tf = logical 0 k = 2 3 6 8 10 11 13 14 2 tf = logical 0 k = 2 5 6 8 11 12 15 2 tf = logical 0 k = 2 14 11 8 6 3 2 tf = logical 1 k = 1 15 12 10 7 6 3 1 tf = logical 1 k = 2 4 6 8 12 14 2 tf = logical 0 k = 1 5 6 7 10 11 14 1 tf = logical 0