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

조회 수: 8 (최근 30일)
mark palmer
mark palmer 2020년 6월 26일
댓글: darova 2020년 6월 28일
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!
darova
darova 2020년 6월 28일
im just doing my job

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by