Azzera filtri
Azzera filtri

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

22 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

darova
darova il 27 Giu 2020
The best way is described here: Interpolation of 3D point data
  2 Commenti
mark palmer
mark palmer il 27 Giu 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!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by