Cody

Solution 1571309

Submitted on 29 Jun 2018 by bainhome
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
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
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
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
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
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   Pass
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

7   Pass
X = [-1 -0.5 0.5 1]; Y = [0 sqrt(3)/2 sqrt(3)/2 0]; tf = isrectangle(X,Y); assert(~tf) %trapezoid X = [0 10 0 5]; Y = [0 0 0 5]; tf = isrectangle(X,Y); assert(~tf) %triangle with doubled vertex

Suggested Problems

More from this Author46