Filter löschen
Filter löschen

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

22 Ansichten (letzte 30 Tage)
mark palmer
mark palmer am 26 Jun. 2020
Kommentiert: darova am 28 Jun. 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.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by