Cody

Solution 528991

Submitted on 14 Nov 2014
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

Test Status Code Input and Output
1   Pass
%% Random integer vertices rng default for ii=1:100 X = randi([-1000,1000],4,1); Y = randi([-1000,1000],4,1); tf = isrectangle(X,Y); assert(~tf) %all of these should not be valid rectangles end

2   Pass
%% Random real-valued vertices rng default for ii=1:100 X = -1000+2000*rand(4,1); Y = -1000+2000*rand(4,1); tf = isrectangle(X,Y); assert(~tf) %all of these should not be valid rectangles end

3   Pass
%% Axis-aligned rectangles with integer vertices rng default for ii=1:100 X = randi([-1000,1000],2,1); X = [X;X]; Y = randi([-1000,1000],2,1); Y = [Y;flipud(Y)]; randorder = randperm(4); X = X(randorder); Y = Y(randorder); tic; tf = isrectangle(X,Y); assert(tf) %all of these should be valid rectangles end

4   Pass
%% Axis-aligned rectangles with real-valued vertices rng default for ii=1:100 X = -1000+2000*rand(2,1); X = [X;X]; Y = -1000+2000*rand(2,1); Y = [Y;flipud(Y)]; randorder = randperm(4); X = X(randorder); Y = Y(randorder); tf = isrectangle(X,Y); assert(tf) %all of these should be valid rectangles end

5   Pass
%% General rectangles rng default for ii=1:100 X = randi([-1000,1000],2,1); X = [X;X]; Y = randi([-1000,1000],2,1); Y = [Y;flipud(Y)]; randorder = randperm(4); X = X(randorder); Y = Y(randorder); theta = randi(360); T1 = [1 0 -mean(X); 0 1 -mean(Y); 0 0 1]; R = [cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1]; T2 = [1 0 mean(X); 0 1 mean(Y); 0 0 1]; P = [X(:),Y(:),ones(size(X(:)))]; Q = T2*R*T1*P'; %rotate the points X = Q(1,:)'; Y = Q(2,:)'; tf = isrectangle(X,Y); assert(tf) %all of these should be valid rectangles end

6   Fail
%% Parallelograms that are not rectangles rng default for ii=1:100 X = -1000+2000*rand(2,1); dx = -100+200*rand; dy = -100+200*rand; X = [X;X+dx]; Y = [0;0;dy;dy]; randorder = randperm(4); X = X(randorder); Y = Y(randorder); tf = isrectangle(X,Y); assert(~tf) %all of these should not be valid rectangles end

Error: Assertion failed.