How to remove lines' segments located outside square?
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi all, The following code is used to draw multiple lines and square of area (1x1);
%%PLOT lines
deg = 0 : 5 : 90;
r=2;
x_ax = r*[zeros(size(deg(:))) cosd(deg(:))];
y_ax = r*[zeros(size(deg(:))) sind(deg(:))];
plot(x_ax', y_ax', 'LineWidth',1)
hold on
%%Plot square
x1=0;
x2=1;
y1=0;
y2=1;
x = [x1, x2, x2, x1, x1];
y = [y1, y1, y2, y2, y1];
plot(x, y, 'b-', 'LineWidth', 2.5);
grid on
grid minor
axis equal
xlim([-0.2,1.2])
ylim([-0.2,1.2])
The output would be as the following image;
My question is;
How to remove the multiple lines' segments that are located outside the (1x1) square?
So, the output should be like that;
Any suggestions for code to do that?
댓글 수: 1
Image Analyst
2020년 2월 1일
Original question by Erman, in case he also deletes this one:
How to remove the multiple lines' segments that are located outside the (1x1) square?
Hi all, The following code is used to draw multiple lines and square of area (1x1);
%%PLOT lines
deg = 0 : 5 : 90;
r=2;
x_ax = r*[zeros(size(deg(:))) cosd(deg(:))];
y_ax = r*[zeros(size(deg(:))) sind(deg(:))];
plot(x_ax', y_ax', 'LineWidth',1)
hold on
%%Plot square
x1=0;
x2=1;
y1=0;
y2=1;
x = [x1, x2, x2, x1, x1];
y = [y1, y1, y2, y2, y1];
plot(x, y, 'b-', 'LineWidth', 2.5);
grid on
grid minor
axis equal
xlim([-0.2,1.2])
ylim([-0.2,1.2])
The output would be as the following image;
My question is;
How to remove the multiple lines' segments that are located outside the (1x1) square?
So, the output should be like that;
Any suggestions for code to do that?
채택된 답변
KSSV
2018년 9월 11일
clc; clear all ;
%%PLOT lines
deg = 0 : 5 : 90;
r=2;
x_ax = r*[zeros(size(deg(:))) cosd(deg(:))];
y_ax = r*[zeros(size(deg(:))) sind(deg(:))];
plot(x_ax', y_ax', 'LineWidth',1)
hold on
%%Plot square
x1=0;
x2=1;
y1=0;
y2=1;
x = [x1, x2, x2, x1, x1];
y = [y1, y1, y2, y2, y1];
plot(x, y, 'b-', 'LineWidth', 2.5);
grid on
grid minor
axis equal
xlim([-0.2,1.2])
ylim([-0.2,1.2])
%%Get points lying inisde square
figure
hold on
plot(x, y, 'b-', 'LineWidth', 2.5);
grid on
grid minor
axis equal
xlim([-0.2,1.2])
ylim([-0.2,1.2])
t = linspace(0,1,1000)' ;
for i = 1:size(x_ax,1)
xi = (1-t)*x_ax(i,1)+t*x_ax(i,2) ;
yi = (1-t)*y_ax(i,1)+t*y_ax(i,2) ;
%
idx = inpolygon(xi, yi,x', y') ;
plot(xi(idx), yi(idx))
end
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!