Cody

# Problem 2671. Check if vertices form a rectangle

Solution 2888801

Submitted on 29 Aug 2020
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   Fail
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

Not enough input arguments. Error in assessFunctionPresence Error in isrectangle (line 2) assessFunctionPresence Error in Test1 (line 5) tf = isrectangle(X,Y);

2   Fail
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

Not enough input arguments. Error in assessFunctionPresence Error in isrectangle (line 2) assessFunctionPresence Error in Test2 (line 5) tf = isrectangle(X,Y);

3   Fail
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

Not enough input arguments. Error in assessFunctionPresence Error in isrectangle (line 2) assessFunctionPresence Error in Test3 (line 8) tic; tf = isrectangle(X,Y);

4   Fail
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

Not enough input arguments. Error in assessFunctionPresence Error in isrectangle (line 2) assessFunctionPresence Error in Test4 (line 8) tf = isrectangle(X,Y);

5   Fail
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

Not enough input arguments. Error in assessFunctionPresence Error in isrectangle (line 2) assessFunctionPresence Error in Test5 (line 18) tf = isrectangle(X,Y);

6   Fail
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

Not enough input arguments. Error in assessFunctionPresence Error in isrectangle (line 2) assessFunctionPresence Error in Test6 (line 11) tf = isrectangle(X,Y);

7   Fail
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

Not enough input arguments. Error in assessFunctionPresence Error in isrectangle (line 2) assessFunctionPresence Error in Test7 (line 3) tf = isrectangle(X,Y);

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!