Cody

# Problem 194. Clockwise or Counterclockwise

Solution 1223482

Submitted on 1 Jul 2017 by HH
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))

ans = 1 1 -1 -1 1 -1 -1 1 ans = logical 1

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

ans = -0.5000 -0.5000 0.5000 0.5000 1.0000 -1.0000 -1.0000 1.0000 ans = logical 0

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

ans = -0.5000 -0.5000 0.5000 0.5000 1.0000 -1.0000 -1.0000 1.0000 ans = 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))

ans = 3.5000 4.5000 -0.5000 -3.5000 -3.5000 -0.5000 -7.6667 3.3333 9.3333 7.3333 -3.6667 -8.6667 ans = 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))

ans = 11.2667 11.2667 7.2667 3.2667 2.2667 -1.7333 -2.7333 -2.7333 -8.7333 -7.7333 -7.7333 -6.7333 -1.7333 2.2667 2.2667 36.8667 1.8667 -26.1333 -18.1333 -3.1333 -1.1333 -11.1333 -21.1333 -23.1333 -8.1333 2.8667 13.8667 16.8667 19.8667 19.8667 ans = 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))

ans = 2.2667 2.2667 -1.7333 -6.7333 -7.7333 -7.7333 -8.7333 -2.7333 -2.7333 -1.7333 2.2667 3.2667 7.2667 11.2667 11.2667 19.8667 19.8667 16.8667 13.8667 2.8667 -8.1333 -23.1333 -21.1333 -11.1333 -1.1333 -3.1333 -18.1333 -26.1333 1.8667 36.8667 ans = logical 0

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

ans = 0.5000 0.5000 -0.5000 -0.5000 -0.5000 0.5000 0.5000 -0.5000 ans = logical 0

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

ans = -0.5000 -0.5000 0.5000 0.5000 -0.5000 0.5000 0.5000 -0.5000 ans = logical 1

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

ans = -1 -1 1 1 0 -2 0 2 ans = logical 0

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

ans = 1 1 -1 -1 2 0 -2 0 ans = 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)))

ans = -0.0387 -0.3208 -0.4761 -0.1700 -0.1887 -0.3399 -0.5599 -0.1787 -0.0036 0.4397 0.4307 0.2617 0.8397 0.0859 0.2188 0.1133 0.7298 0.4559 0.0815 0.0245 -0.1232 -0.6259 -0.5100 -0.1843 -0.6824 -0.2621 -0.0088 0.2852 0.1411 0.5656 ans = logical 0 ans = -0.0311 -0.0026 0.6221 0.1236 0.8168 0.7124 0.6116 -0.0079 -0.0491 -0.0741 -0.6915 -0.1376 -0.8545 -0.8153 -0.2225 0.1035 0.0450 0.6787 0.0520 -0.0252 -0.3529 -0.7398 -0.0538 -0.2320 -0.0966 -0.4770 -0.0317 0.1843 0.5908 0.3547 ans = logical 1 ans = 0.1174 -0.1029 -0.3200 -0.5106 -0.6790 -0.8282 -0.0424 -0.1075 0.0870 0.3885 0.6029 0.0468 0.5979 0.4206 0.3295 0.5668 0.4876 0.4226 0.2628 0.0191 -0.3584 -0.0890 -0.4149 -0.6262 -0.6497 -0.4376 -0.0041 0.0987 0.2568 0.4655 ans = logical 0 ans = 0.0821 -0.0040 -0.3104 -0.0802 -0.6921 -0.4229 -0.5352 -0.1686 -0.1569 0.0843 0.1968 0.6759 0.5141 0.5867 0.2304 0.2479 0.3880 0.8150 0.0938 0.3083 0.0263 -0.2071 -0.1270 -0.4082 -0.7620 -0.3203 -0.4349 -0.0555 0.1935 0.2423 ans = logical 0 ans = -0.0819 0.2773 0.2334 0.1479 0.8865 0.0974 0.0191 0.2741 -0.0855 -0.3624 -0.1100 -0.4838 -0.2477 -0.3637 -0.2006 0.6484 0.9049 0.2727 0.0709 0.0078 -0.0460 -0.0297 -0.8427 -0.8068 -0.6268 -0.0757 -0.1057 0.0486 0.2535 0.3267 ans = logical 1 ans = 0.9451 0.3138 0.2849 0.0184 -0.2898 -0.6700 -0.8484 -0.3982 -0.0816 -0.0511 -0.0292 0.0314 0.0539 0.5210 0.1997 -0.1131 -0.1054 -0.3949 0.0598 -0.6514 -0.5447 -0.1920 0.1600 0.1868 0.2189 0.3017 0.2436 0.1983 0.4656 0.1668 ans = logical 1 ans = -0.1293 -0.6774 -0.7882 -0.1695 -0.3801 -0.3289 -0.0968 0.0932 0.5588 0.3700 0.6703 0.8422 0.1247 -0.0061 -0.0828 -0.1623 -0.5138 -0.2179 -0.0256 0.1716 0.3856 0.1942 0.4896 0.6850 0.1624 -0.0262 -0.4217 -0.2457 -0.2130 -0.2623 ans = logical 1 ans = -0.4468 -0.2313 0.0234 0.3400 0.7441 0.2459 0.8668 0.0310 0.1439 0.1037 -0.1748 -0.3003 -0.5277 -0.3533 -0.4645 -0.3831 -0.5245 -0.5665 -0.6320 -0.5573 -0.0145 0.1908 0.0792 0.2867 0.7497 0.6821 0.4166 0.3202 0.0728 -0.1202 ans = logical 0 ans = 0.3963 0.2055 0.1255 0.8239 0.1118 0.3479 -0.0469 -0.2598 -0.4518 -0.1542 -0.2646 -0.2920 -0.1927 -0.3334 -0.0156 0.8201 0.1928 0.0246 -0.2136 -0.1657 -0.7735 -0.4055 -0.5524 -0.4263 -0.0506 -0.0212 0.0696 0.0951 0.7312 0.6754 ans = logical 1 ans = -0.7244 -0.4454 -0.0328 0.1893 0.5697 0.3900 0.4923 0.9224 0.3356 0.3096 0.0711 -0.0956 -0.6796 -0.6995 -0.6028 -0.4663 -0.7542 -0.6602 -0.3482 -0.5381 -0.0948 0.0436 0.3946 0.3259 0.6852 0.1426 0.3926 0.6645 0.2636 -0.0507 ans = logical 0 ans = -0.8610 -0.2202 -0.9250 -0.0630 -0.0426 -0.0353 0.1910 0.0293 0.6168 0.4353 0.5465 0.5577 0.0220 -0.1819 -0.0695 0.4147 -0.0560 -0.3572 -0.1071 -0.1052 -0.4988 -0.5918 -0.1333 -0.2972 -0.0351 0.2454 0.7107 0.1537 0.6801 -0.0230 ans = logical 0 ans = -0.1631 -0.5934 -0.2151 -0.0752 0.3182 0.1932 0.7552 0.5697 0.4070 0.4214 0.0425 -0.1979 -0.5673 -0.8411 -0.0542 0.0500 0.4761 0.3669 0.8953 0.9139 0.2448 0.3077 -0.0262 -0.2227 -0.5771 -0.3257 -0.8691 -0.7636 -0.4844 0.0142 ans = logical 1 ans = 0.0525 0.2804 0.2066 0.7600 0.0765 0.0774 0.3340 0.0208 -0.1651 -0.3469 -0.1433 -0.3492 -0.2325 -0.5232 -0.0480 0.9594 0.5475 0.1610 0.1493 -0.0511 -0.1154 -0.6815 -0.6575 -0.3900 -0.3594 -0.0680 -0.0260 0.0565 0.4996 -0.0244 ans = logical 1 ans = -0.0352 -0.2973 -0.0538 -0.4602 -0.7140 -0.2598 -0.0259 -0.0045 0.3317 -0.0229 0.7766 0.3998 0.3920 0.0915 -0.1180 -0.0280 0.0913 -0.0377 -0.2174 -0.7608 -0.6945 -0.0431 -0.0787 -0.3141 -0.0393 0.1090 0.2534 0.6416 0.8454 0.2730 ans = logical 0 ans = -0.5620 -0.4768 -0.4510 -0.3647 -0.0935 0.0567 0.1330 0.6851 0.7971 0.7296 0.3375 0.0153 -0.1274 -0.4895 -0.1893 0.0735 -0.1178 -0.3049 -0.5283 -0.2157 -0.4542 -0.2722 -0.3876 -0.0498 0.3060 0.4049 0.2194 0.5681 0.7088 0.0498 ans = logical 0 ans = 0.0881 0.3391 0.3258 0.8652 0.6474 0.2102 0.1194 -0.1153 -0.2744 -0.2706 -0.6239 -0.6084 -0.3232 -0.2608 -0.1185 -0.4828 -0.4353 -0.1645 0.0623 0.3946 0.3977 0.9079 0.0452 0.2387 0.0927 0.0610 -0.1562 -0.1940 -0.3317 -0.4356 ans = logical 0 ans = 0.7304 0.2041 0.2195 0.0885 -0.1359 -0.4696 -0.2954 -0.2770 -0.2026 -0.7380 -0.0737 -0.0827 0.2570 0.4369 0.3384 0.0175 0.1197 0.3069 0.4364 0.7558 0.7132 0.1805 0.0496 -0.0324 -0.5187 -0.0497 -0.4391 -0.8699 -0.5115 -0.1581 ans = logical 0 ans = -0.0988 -0.6776 -0.7419 -0.1035 -0.1428 -0.4202 -0.0430 0.0016 0.1868 0.6752 0.9005 0.1171 0.1228 0.2699 -0.0461 0.0645 0.4976 0.1543 -0.0744 -0.1283 -0.6023 -0.0875 -0.2489 -0.3715 -0.4704 -0.1569 -0.0147 0.0813 0.6441 0.7131 ans = logical 0 ans = -0.7541 -0.7657 -0.0330 -0.1387 0.0382 0.0954 0.4834 0.8255 0.2622 0.5844 0.1067 -0.0257 -0.3004 -0.0658 -0.3124 0.1182 0.4723 0.0532 0.6036 0.3107 0.1964 0.3251 0.1216 -0.0566 -0.5143 -0.2549 -0.7372 -0.5803 -0.0022 -0.0556 ans = logical 1 ans = 0.0199 -0.0540 -0.5447 -0.1587 -0.2827 -0.8866 -0.2619 -0.0593 0.1004 0.3805 0.3419 0.4169 0.6318 0.3091 0.0475 0.4536 0.1950 0.6533 0.1411 0.0759 -0.3220 -0.2021 -0.0637 -0.9002 -0.5864 -0.1733 -0.0070 0.2250 0.3207 0.1903 ans = logical 0 ans = -0.0055 0.2312 0.6332 0.5887 0.4812 0.7072 0.3237 0.1565 -0.0164 -0.3318 -0.6210 -0.4252 -0.9111 -0.7333 -0.0773 -0.3740 -0.5697 -0.6298 -0.2198 0.0258 0.3349 0.3580 0.4384 0.3777 0.6150 0.4709 0.1050 -0.2007 -0.5579 -0.1737 ans = logical 0 ans = 0.0386 -0.0550 -0.3209 -0.8186 -0.7702 -0.0687 -0.1130 0.0445 0.1240 0.3154 0.3070 0.6434 0.2057 0.2961 0.1718 -0.6326 -0.2223 -0.2778 -0.1877 0.1880 0.1422 0.3525 0.3121 0.1830 0.3182 0.1501 0.0615 -0.0087 -0.1785 -0.1999 ans = logical 1 ans = -0.2934 -0.1984 -0.0984 0.1932 0.5852 0.5681 0.3916 0.1907 -0.0370 -0.1013 -0.3622 -0.2410 -0.3069 -0.1461 -0.1443 -0.2540 -0.3285 -0.2038 -0.5106 -0.4801 -0.1337 0.1123 0.2308 0.1498 0.8869 0.5295 0.0676 0.0238 -0.0414 -0.0487 ans = logical 0 ans = 0.7464 0.2169 0.4255 0.3186 -0.0598 -0.1241 -0.2177 -0.5184 -0.2487 -0.3127 -0.3602 -0.3814 -0.1467 0.1363 0.5261 -0.3093 0.0820 0.3093 0.5337 0.2022 0.3837 0.3041 0.4068 0.1237 0.0480 -0.0927 -0.3772 -0.2867 -0.6918 -0.6359 ans = logical 0 ans = 0.4001 0.0889 -0.1002 -0.0749 -0.4725 -0.8930 -0.0769 -0.4298 -0.1303 0.0706 0.0670 0.4757 0.4082 0.1301 0.5370 -0.5794 -0.2629 -0.4474 -0.1205 -0.1997 0.0445 0.0933 0.5953 0.6616 0.0865 0.0338 0.3165 0.0949 0.0125 -0.3290 ans = logical 1 ans = -0.4088 -0.1349 -0.2573 0.0750 0.3616 0.1423 0.5812 0.7714 0.0965 0.1803 0.0714 -0.0589 -0.3504 -0.4296 -0.6398 -0.1156 -0.1364 -0.7191 -0.4397 -0.5779 -0.0173 -0.1036 0.1430 0.0713 0.2210 0.0964 0.5611 0.5909 0.3190 0.1070 ans = logical 0 ans = 0.2452 0.1905 -0.1224 -0.3894 -0.3942 -0.5436 -0.5721 -0.0467 -0.2641 -0.0107 0.3155 0.5022 0.3322 0.1506 0.6068 0.3086 0.8716 0.5170 0.4953 0.1900 0.0237 -0.2152 -0.0699 -0.6005 -0.3875 -0.7762 -0.5017 -0.1490 -0.0203 0.3141 ans = logical 0 ans = -0.2859 0.0174 0.4039 0.7478 0.2783 0.0930 0.5260 0.5044 0.1105 -0.0548 -0.1706 -0.5197 -0.4806 -0.4598 -0.7099 -0.5716 -0.8022 -0.7566 -0.5405 0.0190 0.1165 0.4302 0.8481 0.7387 0.3025 0.3164 0.3813 0.1403 -0.0574 -0.5647 ans = logical 0 ans = 0.1003 0.4849 0.4651 0.6549 0.5434 0.1197 0.3926 0.1186 -0.2008 -0.2784 -0.6820 -0.8923 -0.7305 0.0391 -0.1345 -0.4979 -0.7736 -0.3194 -0.1471 0.0862 0.0327 0.5695 0.6013 0.7692 0.3524 0.3131 -0.0132 -0.3613 -0.0301 -0.5819 ans = logical 0 ans = 0.1223 0.0229 -0.4704 -0.0639 -0.7402 -0.5677 -0.3486 -0.0289 0.0302 0.3276 0.6080 0.2373 0.0930 0.3866 0.3919 0.3883 0.1793 0.7965 0.1252 0.1553 -0.1289 -0.2845 -0.1025 -0.8833 -0.60...