Borrar filtros
Borrar filtros

What's the best way to interpolate the vertices of a polygon?

22 visualizaciones (últimos 30 días)
mark palmer
mark palmer el 26 de Jun. de 2020
Comentada: darova el 28 de Jun. de 2020
What's the best way to interpolate the vertices of a polygon?
Take a triangle with vertices
pKL = [429 92; 326 334; 459 98];
interpp = 5;
interp2(pKL,interpp) % NO!
resample(pKL,interpp,1)) % NO!
How can I get interpp=5 points between 429 and 326, then 326 and 459, then 459 back to 429 in the x direction, and the same idea in the y direction, and combine it all in a single 2D array? I tried interp2d and resample, but it doesn't work. I can do it with a loop, but that feels like too many lines of code.

Respuesta aceptada

darova
darova el 27 de Jun. de 2020
The best way is described here: Interpolation of 3D point data
  2 comentarios
mark palmer
mark palmer el 27 de Jun. de 2020
THANKS! I got the following code to work
pKL = [429 92; 326 334; 459 98]; % TEST ONLY
% X AND Y ARE SWAPPED FOR EXTERNAL REASONS
rx = pKL(:,2)';
ry = pKL(:,1)';
rx = [rx rx(1)];
ry = [ry ry(1)];
inD = 5;
pt = interparc(inD, rx(1:2), ry(1:2), 'spline')
ANS:
pt =
92.0000 429.0000
152.5000 403.2500
213.0000 377.5000
273.5000 351.7500
334.0000 326.0000
but not the example that doesn't use the special function interparc:
t = [0;cumsum(sqrt(diff(rx).^2+diff(ry).^2))];
t = t/t(end);
ti = linspace(0,1,5);
xx = spline(t,x,ti);
yy = spline(t,y,ti);
Anyway, thanks again!
darova
darova el 28 de Jun. de 2020
im just doing my job

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by