Finding intersection points in a square.

1 ビュー (過去 30 日間)
HyeongJu Lee
HyeongJu Lee 2021 年 11 月 22 日
編集済み: Matt J 2021 年 11 月 22 日
Hello,
Is there good way to find the intersection points in a square.
Also, can I get intersection points between the lines?
I spent pretty much time but cannot solve it. (I am practing MATLAB now)
Please help me..

回答 (1 件)

Matt J
Matt J 2021 年 11 月 22 日
編集済み: Matt J 2021 年 11 月 22 日
Yes, you can use,
square=polyshape([0 0; 0 1; 1 1; 1 0]);
line=[0.01,1,-0.6];
out=linexlines2D(square,line) %intersections
out = 2×2
0 1.0000 0.6000 0.5900
plot(square)
hold on
fimplicit(@(x,y) [x(:),y(:),x(:).^0]*line(:));
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.
plot(out(1,:),out(2,:),'o','MarkerFaceColor','r');
hold off
xlim([-1,2])
axis equal

Community Treasure Hunt

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

Start Hunting!

Translated by