多边形边界上彼此距离相等的点(坐标)-Matlab
我正在考虑以下问题的解决方案:如何在多边形边界(多边形对象)上找到彼此距离相等的X点(坐标)。我甚至不知道如何处理它,所以欢迎任何关于如何处理它的想法 代码:多边形边界上彼此距离相等的点(坐标)-Matlab,matlab,Matlab,我正在考虑以下问题的解决方案:如何在多边形边界(多边形对象)上找到彼此距离相等的X点(坐标)。我甚至不知道如何处理它,所以欢迎任何关于如何处理它的想法 代码: 将LengthToGo设置为SegemntP 在多边形上选择一个起点 将你的长度移动到下一点 如果你没有达到这一点,你已经找到了你的一个要点。将此作为新的起点,然后继续0 如果您已到达该点,则将长度ToGo减去起点和您已到达的点之间的距离。将你到达的点设置为你的新起点。继续0 希望下面的代码能够解释: clc; clear all; cl
SegemntP
clc;
clear all;
close all;
numOfSegments = 10; % just an example
polygon = polyshape([0 5 15 15 20 18 10 20 20],[1 5 10 10 10 15 10 25 35]);
% polygon = polyshape([0 20 20 0 0],[0 0 20 20 0]);
plot(polygon)
hold on;
P = perimeter(polygon);
SegemntP = P/numOfSegments;
% this is first point on the polygon
lastPoint = polygon.Vertices(1,:);
% container for points
points = lastPoint;
polyIdx = 1;
lenToGo = SegemntP;
plygonPoints = [polygon.Vertices;polygon.Vertices(1,:)];% add first point so polygon is closed
while(size(points,1)<numOfSegments)
lenOnPolyline = norm(plygonPoints(polyIdx+1,:)-lastPoint);
if lenOnPolyline > lenToGo
% move on this line
dir = plygonPoints(polyIdx+1,:)-lastPoint;
dir = dir ./ norm(dir);
lastPoint = dir*lenToGo+lastPoint;
points = [points;lastPoint];
lenToGo = SegemntP;
else
% go to next line segment
lenToGo = lenToGo-lenOnPolyline;
polyIdx = polyIdx +1;
lastPoint = plygonPoints(polyIdx,:);
end
end
plot(points(:,1),points(:,2),'b*')
axis equal
clc;
清除所有;
全部关闭;
numOfSegments=10;%只是一个例子
多边形=多形([0 5 15 20 18 10 20 20],[1 5 10 10 10 10 25 35]);
%多边形=多边形([02000],[02000]);
绘图(多边形)
等等
P=周长(多边形);
SegemntP=P/numOfSegments;
%这是多边形上的第一个点
lastPoint=多边形。顶点(1,:);
%积分容器
点=最后一点;
polyIdx=1;
lenToGo=SegemntP;
plygonPoints=[多边形.顶点;多边形.顶点(1,:)];%添加第一个点,使多边形闭合
而(尺寸(点,1)多哥
%走这条线
dir=plygonPoints(polyIdx+1,:)-lastPoint;
dir=dir./norm(dir);
lastPoint=dir*lenToGo+lastPoint;
点=[点;最后一点];
lenToGo=SegemntP;
其他的
%转到下一个线段
lenToGo=lenToGo-lenOnPolyline;
polyIdx=polyIdx+1;
lastPoint=plygonPoints(polyIdx,:);
结束
结束
绘图(点(:,1),点(:,2),'b*')
轴相等
结果:
什么样的距离?沿多边形,还是欧几里德?谢谢。沿多边形是我最初的想法,但如果不贪婪,欧几里德也会很有趣地查看和比较。沿多边形相当简单:获得多边形的长度,除以点数,然后将一个点等距放置。另一个点不在一切都很简单,可能需要彻底的搜索。谢谢,我添加了它的边界(周长)的长度之和然后除以numOfSegments。我如何从这里开始以相等的距离放置一个点?谢谢。非常酷。我如何设置起点始终是多边形最左边的点?如何计算每个点?我添加了
str=1:numOfSegments;
文本(点(:,1)+.5,点(:,2)+.5,字符串(str);
clc;
clear all;
close all;
numOfSegments = 10; % just an example
polygon = polyshape([0 5 15 15 20 18 10 20 20],[1 5 10 10 10 15 10 25 35]);
% polygon = polyshape([0 20 20 0 0],[0 0 20 20 0]);
plot(polygon)
hold on;
P = perimeter(polygon);
SegemntP = P/numOfSegments;
% this is first point on the polygon
lastPoint = polygon.Vertices(1,:);
% container for points
points = lastPoint;
polyIdx = 1;
lenToGo = SegemntP;
plygonPoints = [polygon.Vertices;polygon.Vertices(1,:)];% add first point so polygon is closed
while(size(points,1)<numOfSegments)
lenOnPolyline = norm(plygonPoints(polyIdx+1,:)-lastPoint);
if lenOnPolyline > lenToGo
% move on this line
dir = plygonPoints(polyIdx+1,:)-lastPoint;
dir = dir ./ norm(dir);
lastPoint = dir*lenToGo+lastPoint;
points = [points;lastPoint];
lenToGo = SegemntP;
else
% go to next line segment
lenToGo = lenToGo-lenOnPolyline;
polyIdx = polyIdx +1;
lastPoint = plygonPoints(polyIdx,:);
end
end
plot(points(:,1),points(:,2),'b*')
axis equal