How can I plot different quadrilateral with different range of coordinates per node?

I have a square with dimension of 50x50 with four nodes, each node will vary in range of (-10,10) which means each corner of the square has 3 nodes along x axis (Fig below)
I want to connect each node per corner to nodes in other corners in order to make different quadrilateral with different shape. For this special case It would be 3^4=81 different shapes and I need to plot them as subplot (8,8,n), I have written intial part of the code but I dont know how to connect all coressponding nodes to each other to make 64 different quadrilateral. Could you please tell me how to do this? Thanks
clc;
clear;
close all;
x = [-25; 25; 25; -25];
y = [-25; -25; 25; 25];
for i=1:4
for j=-10:10:10
x(i,:)=x(i,:)+j;
Y(:,:)=y;
subplot(2,2,i);
plot(x,y,'.');
xlim([-50 50])
ylim([-50 50])
k = boundary(x,y);
hold on;
plot(x(k),y(k));
end
end

 Accepted Answer

Look at my soultion
clc,clear
x = [-1 1 1 -1]*25;
y = [-1 -1 1 1]*25;
plot(x,y,'or'); % plot original nodes
axis([-1 1 -1 1]*40) % axes boundaries
hold on
k = 0;
for i = 1:4
for j = -10:10:10
x1 = x; % create a copy of "x"
x1(i) = x1(i) + j; % modify current node
% k = k + 1;
% subplot(4,3,k)
h = plot([x1 x1(1)],[y y(1)],'.-b');
pause(1)
delete(h);
end
end
hold off
Do you like it?

4 Comments

Sounds Great Darova! Thanks for the time you have invested. I wrote the code as below to ceate a 27X4 Struct, each member has two fields (x and y cordinate). Each row contains 4 nodes to make a quadrilateral.
Untitled2.jpg
clear;
close all;
x=[-30;-25;-20;20;25;30;30;25;20;-20;-25;-30];
y=[-25;-25;-25;-25;-25;-25;25;25;25;25;25;25];
i=x(1:end);
j=y(1:end);
M=[i,j];
s.x=[];
s.y=[];
c=repmat(s,12,1);
c(1).x=M(1,1);
c(1).y=M(1,2);
c(2).x=M(2,1);
c(2).y=M(2,2);
c(3).x=M(3,1);
c(3).y=M(3,2);
c(4).x=M(4,1);
c(4).y=M(4,2);
c(5).x=M(5,1);
c(5).y=M(5,2);
c(6).x=M(6,1);
c(6).y=M(6,2);
c(7).x=M(7,1);
c(7).y=M(7,2);
c(8).x=M(8,1);
c(8).y=M(8,2);
c(9).x=M(9,1);
c(9).y=M(9,2);
c(10).x=M(10,1);
c(10).y=M(10,2);
c(11).x=M(11,1);
c(11).y=M(11,2);
c(12).x=M(12,1);
c(12).y=M(12,2);
for i=1:27
j=c(1);
k=c(4);
l=c(7);
o=c(10);
d(i,:)=[j;k;l;o];
for i=1:3:25 %#ok<*FXSET>
o=c(10);
d(i,:)=[j;k;l;o];
for i=2:3:26
o=c(11);
d(i,:)=[j;k;l;o];
for i=3:3:27
o=c(12);
d(i,:)=[j;k;l;o];
end
end
end
I have changed the members of cloumn 4 and all other membesr are unchanged, The other members excpet column 4 are going to change in the 2nd part of code as below,
But, clolumn 4 is also changing. for instance: d(4,4) in the top loop is (-25,25) but in the bottom loop changed to (-30,25). How can I keep the 4th column of "d" unchanged in the below:
for i=4:6
k=c(5);
d(i,:)=[j;k;l;o];
end
for i=7:9
k=c(6);
d(i,:)=[j;k;l;o];
end
for i=10:18
l=c(8);
d(i,:)=[j;k;l;o];
end
for i=13:15
k=c(5);
d(i,:)=[j;k;l;o];
end
for i=16:18
k=c(6);
d(i,:)=[j;k;l;o];
end
for i=19:27
l=c(9);
d(i,:)=[j;k;l;o];
for i=22:24
k=c(5);
d(i,:)=[j;k;l;o];
end
for i=25:27
k=c(6);
d(i,:)=[j;k;l;o];
end
end
end
What is your script suppose to do?
Don't understand how can i help you
You can use for loop to create c vector
c(1).x=M(1,1);
c(1).y=M(1,2);

Sign in to comment.

More Answers (1)

Thanks for your reply. This script is a part of bigger script. The main script should creates n^m different quadrilateral from 12 nodes. ( where, n is number of nodes per corner of quadrilateral and m is the number of corners of quadrilateral which in this case is 3^4=81) You can see the coordinate of tthe nodes in the first part as x and y. I labeled each node from 1 to 12 like figure in the first qustion. For instance: nodes with labels 1-4-7-10 create a first quadrilateral and the 1-4-7-11, 1-4-7-12 1-5-7-10,1-5-7-11 and 1-5-712 are respectively for the 2nd to 6th quadrilarerals and so on... to make 81 quadrilateral with different gemoetry.
you can see all the labels and the coordinates of the nodes in the attached excel file.
Also, I attached my main code.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!