clear all
Window=10
square=[0 0; 0 Window; Window 0; Window Window];
N=5;
X1=rand(N,1)*(10+0.1)+0.1;
X2=rand(N,1)*(10+0.1)+0.1;
Y1=rand(N,1)*(10+0.1)+0.1;
Y2=rand(N,1)*(10+0.1)+0.1;
A = [X1(:), X2(:)]; B =[Y1(:), Y2(:)];
ABx=[X1(:), X2(:)];
reshape(ABx,1,[]);
transpose(ABx);
ABx.';
ABx(:);
ABx=reshape(ABx.',1,[]);
ABy=[Y1(:), Y2(:)];
reshape(ABy,1,[]);
transpose(ABy);
ABy.';
ABy(:);
ABy=reshape(ABy.',1,[]);
pos = 3:3:((((length(ABy))/2)-1)*3);
[r,c] = size(ABy);
add = numel(pos);
Xnew = NaN(r,c+add);
Ynew = NaN(r,c+add);
idx = setdiff(1:c+add,pos);
Xnew(1,idx) = ABx;
Ynew(1,idx) = ABy;
Inter=intersections(Xnew,Ynew);
figure, plot(A.',B.','LineWidth', 0.75)
grid on
axis square
axis([0 Window 0 Window])
3 Comments
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/478177-line-pathway-using-intersection-points#comment_740553
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/478177-line-pathway-using-intersection-points#comment_740553
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/478177-line-pathway-using-intersection-points#comment_740633
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/478177-line-pathway-using-intersection-points#comment_740633
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/478177-line-pathway-using-intersection-points#comment_740642
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/478177-line-pathway-using-intersection-points#comment_740642
Sign in to comment.