Fitting Scattered Data to a Spherical Surface
7 views (last 30 days)
Show older comments
I have a function parameterized by theta = [0,pi] and phi = [0,2*pi) such that F = f(theta, phi).
To get more specific, I have 84 scattered data points, where each point consists of (theta, phi, F) where F denotes the height in the (theta, phi) direction.
I want to fit these scattered data to a uniform grid. I have tried using griddata and Triscatterinterp; however, I still obtain a sphere, and it seems the height function F is ignored completely. Have I done something wrong below in my code? Any help would be greatly appreciated. Thanks.
% I form my grid here: new_th=linspace(0,pi,g_rows); new_ph=linspace(0,2*pi,g_rows); [grid_ph,grid_th]=meshgrid(new_ph,new_th);
% using griddata -- I know v4 is slow, but speed is not the goal here new_F = griddata(theta, phi, F, grid_ph, grid_th,'v4');
%forming the surface x(:,:,1)= (new_F).*sin(grid_th).*cos(grid_ph); x(:,:,2)= (new_F).*sin(grid_th).*sin(grid_ph); x(:,:,3)= (new_F).*cos(grid_th); surf(x(:,:,1),x(:,:,2),x(:,:,3));
2 Comments
Ashish Uthama
on 25 Mar 2011
Formatting your code with the '{} code' button would help make it more readable.
I think you are trying to interpolate spherical data using Cartesian coordinate interpolation. Maybe you could try obtaining your grid points using sph2cart?
Ashish Uthama
on 25 Mar 2011
Also, a runnable sample code helps us give it a spin and try some options (You could make up some dummy data to illustrate your question).
Answers (2)
Ashish Uthama
on 25 Mar 2011
Air code: (havent given it much thought, will try to get back to it later). Consider this a hint for now.
%r phi and th are your scattered data
[x y] = sph2cart(th,phi,ones(size(th)));
%spherical coordinate grid:
gth = linspace(0,pi,20);
gphi = linspace(0,2*pi,20)
%Convert to cartesian coordinates
[gx gy] = sph2cart(gth,gphi,ones(size(gth)));
%Obtain r on the grid
gr = griddata(x,y,r,gx,gy)
0 Comments
Balengi
on 26 Mar 2011
1 Comment
Ashish Uthama
on 28 Mar 2011
You can still edit the existing question.
Try paring down the data, or create dummy data for the sake of this question. You dont need the exact same data, some representative data enough to make readers here understand what needs to be done.
See Also
Categories
Find more on Scatter Plots 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!