How to interpolate a closed polar plot

조회 수: 39 (최근 30일)
Mercedes Stringer Martin
Mercedes Stringer Martin 2022년 7월 27일
답변: Santiago Benito 2022년 9월 16일
Hello, I need some help interpolating a closed polar plot which currently looks like this:
figure(1)
polarplot(deg2rad(Angle),Mag)
When I interpolate it using spline it looks like this:
figure(2)
xint = linspace(0,deg2rad(360),360)';
spl = spline(deg2rad(Angle),Mag);
polarplot(xint,ppval(spl,xint))
This result is almost perfect - however, I want the angle 0 and 360 also to be interpolated/spline/curved rather than a pointed edge.
I have downloaded and tried the interpclosed function (https://uk.mathworks.com/matlabcentral/fileexchange/69055-interpclosed?s_tid=mwa_osa_a) however I get this result:
figure(3)
intc= interpclosed(deg2rad(Angle),Mag, 0:1/360:1);
polarplot(deg2rad(Angle),Mag,'o',intc(1,:),intc(2,:),':.')
Not sure if I'm missing something simple. Any advice to fix this issue would be greatly appreciated!!

채택된 답변

DGM
DGM 2022년 7월 27일
편집: DGM 2022년 7월 27일
EDITED:
You could enforce endslopes, but this is probably more accurate
% the same fake data
Angle = [0 90 180 270 360];
Mag = [5 1 1 1.5 5];
% replicate the data to represent multiple cycles beyond the query range
% make sure to omit duplicate endpoints if necessary
Angle = [Angle(1:end-1)-360 Angle Angle(2:end)+360];
Mag = [Mag(1:end-1) Mag Mag(2:end)];
% this is the same query range
xint = linspace(0,2*pi,360)';
spl = spline(deg2rad(Angle),Mag); % no endslopes defined
polarplot(xint,ppval(spl,xint))
It's probably not necessary to replicate the entire dataset, but you'll probably want a decent number of points to anchor the spline on either side of the query range. It all depends on how many points are in the dataset.
  댓글 수: 1
Mercedes Stringer Martin
Mercedes Stringer Martin 2022년 7월 27일
They both work great!! Thank you very much for the help, greatly appreciated.

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

추가 답변 (1개)

Santiago Benito
Santiago Benito 2022년 9월 16일
Hi, I might be a little late to the party, but here's my solution.
You tried to use interpclosed to solve the issue but the function failed because it expects cartesian coordinates. To overcome this issue, just convert from polar to cartesian and then back to polar. Please see the example below. Note that, as I don't know your dataset, I made up some polar coordinates as rho and theta:
% Make up some data
rho = [14 9 6 4 2 5 6 1 1 1 3 7 4 3 5 1 2 2 14];
theta = linspace(0,360,numel(rho));
% Plot said data
figure, polarplot(deg2rad(theta),rho)
% Convert to cartesian
[x,y] = pol2cart(deg2rad(theta),rho);
% Run interpclosed
intc= interpclosed(x(1:end-1),y(1:end-1),linspace(0,1,3e2),true);
% Convert the fit to polar
[thetaint,rhoint] = cart2pol(intc(1,:),intc(2,:));
% Plot with polarplot
figure, polarplot(deg2rad(theta),rho,'o',thetaint,rhoint,':.')
The results looks like what I would expect from a spline fit.
Cheers,
Santiago

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by