How to fill the space between these lines?

3 views (last 30 days)
untitled2.png
I have 4 sets of values for the lines
1R = [12 0
12 0.5
12 1
12 1.
12 2
12 2.5
12 3
12 3.5
12 4
12 4.5
12 5
12 5.5
12 6
12 6.5
12 7
12 7.5
12 8
12.5 8
13 8
13.5 8
14 8
14.5 8
15 8
15.5 8
16 8
16.5 8
17 8
17.5 8
18 8
18.5 8
19 8
19.5 8
20 8];
2R = [12 20
12 19.5
12 19
12 18.5
12 18
12 17.5
12 17
12 16.5
12 16
12 15.5
12 15
12 14.
12 14
12 13.5
12 13
12 12.5
12 12
12.5 12
13 12
13.5 12
14 12
14.5 12
15 12
15.5 12
16 12
16.5 12
17 12
17.5 12
18 12
18.5 12
19 12
19.5 12
20 12];
1L =[8 0
8 0.5
8 1
8 1.5
8 2
8 2.5
8 3
8 3.5
8 4
8 4.5
8 5
8 5.5
8 6
8 6.5
8 7
8 7.5
8 8
7.5 8
7 8
6.5 8
6 8
5.5 8
5 8
4.5 8
4 8
3.5 8
3 8
2.5 8
2 8
1.5 8
1 8
0.5 8
0 8];
2L=[8 20
8 19.5
8 19
8 18.5
8 18
8 17.5
8 17
8 16.5
8 16
8 15.5
8 15
8 14.5
8 14
8 13.5
8 13
8 12.5
8 12
7.5 12
7 12
6.5 12
6 12
5.5 12
5 12
4.5 12
4 12
3.5 12
3 12
2.5 12
2 12
1.5 12
1 12
0.5 12
0 12
I tried with the following code but I am getting a gap in the middle.
plot(1R(:,1),1R(:,2),'k');
plot(1L(:,1),1L(:,2),'k');
plot(2L(:,1),2L(:,2),'k');
plot(2R(:,1),L(:,2),'k');
patch([1L(:,1); flipud(1R(:,1))], [1L(:,2); flipud(1R(:,2))], [0.6 0.6 0.6]);
patch([1R(:,1); flipud(2R(:,1))], [1R(:,2); flipud(2R(:,2))], [0.6 0.6 0.6]);
patch([1L(:,1); flipud(2L(:,1))], [1L(:,2); flipud(2L(:,2))], [0.6 0.6 0.6]);
patch([2L(:,1); flipud(2R(:,1))], [2L(:,2); flipud(2R(:,2))], [0.6 0.6 0.6]);
How solve this? any help appreciated.

Accepted Answer

Star Strider
Star Strider on 11 Dec 2018
The easiest way is to define two overlapping rectangles:
figure
hold all
patch([L1(end,1); R1(end,1); flipud([L1(end,1); R1(end,1)])], [L2(1,1); R1(end,2); flipud([L2(end,2); R2(end,2)])], [0.6 0.6 0.6], 'EdgeColor',[0.6 0.6 0.6])
patch([L2(1,1); R2(end,2); flipud([L2(1,1); R2(end,2)])], [L2(end,1); L2(end,1); R2(1,2); R2(1,2)], [0.6 0.6 0.6], 'EdgeColor',[0.6 0.6 0.6])
plot(R1(:,1),R1(:,2),'k');
plot(L1(:,1),L1(:,2),'k');
plot(L2(:,1),L2(:,2),'k');
plot(R2(:,1),R2(:,2),'k');
hold off
This works here. It is likely not robust to other matrices.
Another option would be to use the min and max functions to get the limits of the rectangles. That would likely be more robust.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!