Cody

Problem 2671. Check if vertices form a rectangle

Solution 531692

Submitted on 21 Nov 2014
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

Error using isrectangle (line 2) Undefined function 'pdist' for input arguments of type 'double'.

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

Error using isrectangle (line 2) Undefined function 'pdist' for input arguments of type 'double'.

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

Error using isrectangle (line 2) Undefined function 'pdist' for input arguments of type 'double'.

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

Error using isrectangle (line 2) Undefined function 'pdist' for input arguments of type 'double'.

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

Error using isrectangle (line 2) Undefined function 'pdist' for input arguments of type 'double'.

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

Error using isrectangle (line 2) Undefined function 'pdist' for input arguments of type 'double'.

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

Error using isrectangle (line 2) Undefined function 'pdist' for input arguments of type 'double'.

Suggested Problems

More from this Author44

Community Treasure Hunt

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

Start Hunting!