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

22 次查看(过去 30 天)
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.

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by