Interpolated points to be at a certain equal angular distance

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')

Réponses (1)

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 commentaire

mehlil ahmed
mehlil ahmed le 2 Mar 2023
Modifié(e) : mehlil ahmed le 2 Mar 2023
Hi,
First of all. Thank you for your help and I also mentioned that i took help. I do not want to be rude . But now that you have said about copying and using it, I already tried spline and csaps interpolation. As I was not successful ,I used from your suggestion.
Now about using spline and csaps, csapi interpolation without dropping the first point, I was not successfull using that interpolation as well. That's why though about posting it again. This part is basically a very small part of what I am actually doing. I am creating linear hexahedral mesh. The elements seems distorted in the final mesh that's why I thought about changing this part and creating the input mesh points at a certain angular distance.
I am attaching figure for my reference from my other version. As you can see the interpolation using csapi still did not match with the input spline.

Connectez-vous pour commenter.

Catégories

Produits

Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by