- https://www.mathworks.com/help/matlab/ref/double.cumsum.html
- https://www.mathworks.com/help/matlab/ref/double.interp1.html
How to Discretize a Polygon boundary in to equally spaced points?
40 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Prasanna Routray
el 21 de Dic. de 2024 a las 5:50
Editada: Walter Roberson
el 21 de Dic. de 2024 a las 19:17
The following code plots a polygon (Rectangle with curved corners).
%%
clc
clear all
close all
%%
h=polybuffer( polyshape([0.15 0 -0.15 -0.15 -0.15 0 0.15 0.15], [0.25 0.25 0.25 0.10 -0.05 -0.05 -0.05 0.10]),0.1);
pgon1 = polyshape({h.Vertices(:,1)}, {h.Vertices(:,2)});
xb = (pgon1.Vertices(:,1))';
yb = (pgon1.Vertices(:,2))';
xb = xb(:);
yb = yb(:);
figure
plot(xb, yb, 'DisplayName','All Data')
axis([-0.4 0.4 -0.2 0.4])
Currently, I have a set of points near the curved region and very limited over the straight portions. I want to generate a set of boundary points for this polyshape that are equally spaced. How do I do that?
0 comentarios
Respuesta aceptada
Suraj Kumar
el 21 de Dic. de 2024 a las 7:35
Based on my understanding you want to discretize the boundary of a polygon into equally spaced points.
To achieve this, you can refer to the following steps:
1. After defining the polygon, extract its vertices and calculate the Euclidean distances between consecutive vertices.You can use the function 'cumsum' to get the cumulative distances along the boundary.
xb = (pgon1.Vertices(:,1))';
yb = (pgon1.Vertices(:,2))';
distances = [0; cumsum(sqrt(diff(xb).^2 + diff(yb).^2))];
2. Choose the number of equally spaced points and use `linspace` to generate target distances along the perimeter.
numPoints = 30;
equalSpacedDistances = linspace(0, distances(end), numPoints);
3. Then apply `interp1` to interpolate the x and y coordinates at these distances, yielding points uniformly distributed along the boundary.
xEqualSpaced = interp1(distances, xb, equalSpacedDistances);
yEqualSpaced = interp1(distances, yb, equalSpacedDistances);
You can refer to the attached output for a better understanding:
To learn more about 'cumsum' and 'interp1' functions in MATLAB, please refer to the following links:
Happy Coding!
0 comentarios
Más respuestas (1)
Walter Roberson
el 21 de Dic. de 2024 a las 7:48
Editada: Walter Roberson
el 21 de Dic. de 2024 a las 19:17
See John D'errico file exchange contribution interparc https://www.mathworks.com/matlabcentral/fileexchange/34874-interparc
0 comentarios
Ver también
Categorías
Más información sobre Elementary Polygons en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!