Interpolated points to be at a certain equal angular distance
Show older comments
Hello Good people
I posted earlier about fitting a spline to a set of data points given (x,y,z) (see attached file data.mat ) interpolating points on that spline.I need the interpolated points to be at a certain equal angular distance suppose (360 degrees/N , N= being the the number of interpolated points on the closed curve) from the centroid of each spline ( fig 1). I tried using polar cordinate transformations for one spline and getting the outputs (fig 2,3,4) from the bellow code. Though figure 2, 3 seems to do the work, when i am converting the polar cordinates back to cartesian cordinates after the interpolation and plotting them (fig 4) it seems to not exactly match the input spline. Also the curve is not closing. I am not sure how to solve this.
clc;
clear;
clear all;
close all;
load data.mat
x = xyz(2:end,1);
y = xyz(2:end,2);
z = xyz(2:end,3);
centroid_x = mean(x);
centroid_y = mean(y);
centroid_z = mean(z);
[theta,r,z] = cart2pol(x-centroid_x,y-centroid_y,z);
theta_new=linspace(-pi, pi,size(theta,1)) ;
theta_new=[theta_new]';
epi_spline_polar =interp1(theta, r, theta_new, 'linear');
epi_spline_polar=[epi_spline_polar];
figure(1)
polarplot(theta, r)
grid on
hold on
polarplot(theta_new,epi_spline_polar,'bo')
[u,v,z] = pol2cart(theta_new,epi_spline_polar,z);
u = u + centroid_x;
v = v + centroid_y;
figure(2)
plot(x,y,'.b',u,v,'.r');grid
figure(3)
plot3(xyz(:,1),xyz(:,2),xyz(:,3),'ro')
hold on
plot3(u,v,z,'bo')
Answers (1)
John D'Errico
on 2 Mar 2023
Simple. Without even looking at the plots, first...
The curve is not closed. You are clearly using code I wrote, but now fitting a spline. I dropped the first point, because I was fitting a Fourier series to the data. So I did not want to weight that first point with a double weight. But you are using LINEAR interpolation, NOT a spline. And now the first point was not included!
So DON'T DO THIS!!!!!!!!
x = xyz(2:end,1);
y = xyz(2:end,2);
z = xyz(2:end,3);
Do you expect the curves to now be periodic if your data does not wrap around? Don't just copy and paste code without thinking about what the code does.
As far as not matching the input spline, um, again, interp1 with a LINEAR interpolant is NOT even a spline!!!! And even if you did tell interp1 to use a spline interpolant, it would not be identically the same spline, since it was fit in a different way.
1 Comment
mehlil ahmed
on 2 Mar 2023
Edited: mehlil ahmed
on 2 Mar 2023
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!