Fitting Scattered Data to a Spherical Surface
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Ashish Uthama
2011-3-25
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
2011-3-25
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).
回答(2 个)
Ashish Uthama
2011-3-25
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 个评论
Balengi
2011-3-26
1 个评论
Ashish Uthama
2011-3-28
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!