存储交点 - Matlab
Store intersection point - Matlab
如何存储 polyshape 和直线的交点以便绘制它?
脚本 (source):
clc;
clear;
close all;
poly1 = polyshape([0.5 0 1 1.5],[1 0 0 2]);
lineseg = [0.5 0.5; 2 2];
[in,out] = intersect(poly1,lineseg);
plot(poly1)
hold on
plot(in(:,1),in(:,2),'b',out(:,1),out(:,2),'r')
鉴于 in
包含在多边形内部形成线段的点,而 out
包含在多边形外部形成线段的点,我会说任何点都在 in
和out
应该是一个交点。
要找到这些共同点,请使用 this other intersect
function 和 'rows'
选项:
pts = intersect(in, out, 'rows');
scatter(pts(:,1), pts(:,2));
如何存储 polyshape 和直线的交点以便绘制它?
脚本 (source):
clc;
clear;
close all;
poly1 = polyshape([0.5 0 1 1.5],[1 0 0 2]);
lineseg = [0.5 0.5; 2 2];
[in,out] = intersect(poly1,lineseg);
plot(poly1)
hold on
plot(in(:,1),in(:,2),'b',out(:,1),out(:,2),'r')
鉴于 in
包含在多边形内部形成线段的点,而 out
包含在多边形外部形成线段的点,我会说任何点都在 in
和out
应该是一个交点。
要找到这些共同点,请使用 this other intersect
function 和 'rows'
选项:
pts = intersect(in, out, 'rows');
scatter(pts(:,1), pts(:,2));