Fitting Scattered Data to a Spherical Surface

7 views (last 30 days)
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
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
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).

Sign in to comment.

Answers (2)

Ashish Uthama
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)

Balengi
Balengi on 26 Mar 2011
First, thanks for the tips on properly formatting the code.
That being said, I implemented your air code; however, I wasn't able to obtain an accurate looking surface.
If you would like, I can send you the scattered data points through e-mail. It would be easier, than copying and pasting it all here. Thanks.
  1 Comment
Ashish Uthama
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!