简体   繁体   English

多边形边界上彼此距离相等的点(坐标) - Matlab

[英]Points (coordinates) with equal distances from each other on a polygon boundary - Matlab

I was thinking about a solution for the following problem: How to find X points (coordinates) that have equal distances from each other on a polygon boundary (polyshape object.).我正在考虑以下问题的解决方案:如何在多边形边界(polyshape object.)上找到彼此距离相等的 X 点(坐标)。 I do not know even how to approach it so any ideas how to do it are welcome?我什至不知道如何处理它,所以欢迎任何想法如何去做?

Code:代码:

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]);
plot(polygon)
P = perimeter(polygon);
SegemntP = P/numOfSegments;
  1. set LengthToGo to SegemntP将 LengthToGo 设置为SegemntP
  2. Pick a starting point on your polyshape在你的 polyshape 上选择一个起点
  3. Move your LengthToGo towards the next point将您的 LengthToGo 移向下一点
  4. If you don't reach this point, you have found one of your points.如果你没有达到这一点,你已经找到了你的一点。 Use this as your new starting point and continue with 0.将此作为您的新起点并从 0 继续。
  5. If you have reached this point, reduce LengthToGo by the distance of your starting point and the point you have reached.如果您已到达此点,请将 LengthToGo 减少您的起点与您已到达的点的距离。 Set the point you reached to be your new starting point.将您到达的点设置为新的起点。 continue with 0继续 0

Hope the following code explains:希望下面的代码解释:

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

Result:结果:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM