-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_polyline_clipping.m
More file actions
44 lines (39 loc) · 1.09 KB
/
test_polyline_clipping.m
File metadata and controls
44 lines (39 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
% test_polyline_clipping.m
clc
clear
close all
%sline = [0, 6.5; 1.25, 4; 1.25, 0; NaN, NaN; 0.25, 7; 1.75, 4; 1.75, 0];
%for ii=1:10
% sline = [sline; [NaN NaN]; [ii/2+0.25, 7; ii/2+1.75, 4; ii/2+1.75, 0]];
%endfor
sline = [5/2+0.25, 7; 5/2+1.75, 4; 5/2+1.75, 0];
pol2a = [1 2; 7 4; 4 7; 1 2; 2.5 3; 4 5.5; 5.5 4; 2.5 3; 1 2];
figure;
subplot(2,1,1);
plot(sline(:, 1), sline(:, 2));
hold on;
patch(pol2a(:, 1), pol2a(:, 2), 'facecolor', 'y', 'edgecolor', 'b', 'linewidth', 2);
hold off;
grid on;
axis equal;
title('Original polygon and lines');
subplot(2,2,3);
% "AND" operation
patch(pol2a(:, 1), pol2a(:, 2), 'facecolor', 'y', 'edgecolor', 'b', 'linewidth', 2);
hold on;
[olin, nlin] = clipPolyline (sline, pol2a, 1);
plot (olin(:, 1), olin(:, 2), 'r', 'linewidth', 3);
hold off;
grid on;
axis equal;
title('"AND"\Intersect');
subplot(2,2,4);
% Subtract operation
patch(pol2a(:, 1), pol2a(:, 2), 'facecolor', 'y', 'edgecolor', 'b', 'linewidth', 2);
hold on;
[olin, nlin] = clipPolyline(sline, pol2a, 0);
plot (olin(:, 1), olin(:, 2), 'g', 'linewidth', 3);
hold off;
grid on;
axis equal;
title ('Clip\Subtract');