MATLAB Answers

griddata for closed surface

11 views (last 30 days)
I have spherical data [theta, phi, R]: R = f(theta, phi)
I need to interpolate this data. I've used griddata function and got a nice result, but with an issue: it's not interpolated as a closed surface:
it looks like a rumpled orange (as I wanted), but there is no smooth seam line. So the data near edges are not interpolated as needed.
Is there any variants of griddata function for closed manifolds? Or maybe some variants to solve this problem?
I was advised to use scatteredInterpolant:
% Given data [theta phi rho] - Nx1 vectors
% making XYZ scattered data (Nx1 vectors)
[x,y,z] = sph2cart(theta,phi,1);
F = scatteredInterpolant(x,y,z,rho);
% prepare grid for meshing (we'll mesh xyz data, not theta,phi)
nTheta0 = 100; nPhi0 = 100;
theta0 = linspace(-pi, pi, nTheta0);
phi0 = linspace(-pi/2, pi/2, nPhi0);
[theta0, phi0] = meshgrid(theta0, phi0);
% don't know if there is easier way to make rho0 grid
% but this way works too:
rho0 = zeros(nTheta0, nPhi0);
for i=1:nTheta0
for j=1:nPhi0
% current point x y z taken from theta0, phi0 grids
[x_,y_,z_] = sph2cart(theta0(i,j), phi0(i,j), 1);
% interpolated value of this [x y z] point is new rho value
rho0(i,j) = F(x_,y_,z_);
% xyz grids for meshing
[vx,vy,vz] = sph2cart(theta0, phi0, rho0);
figure; mesh(vx,vy,vz);

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 23 Oct 2014
Edited: Mohammad Abouali on 23 Oct 2014
The problem is that it doesn't recognize that phi=360 and phi=0 are actually the same point.
use scatteredInterpolant. You need to convert it to regular cartesian coordinate too.
If you want to use another application ESMF Regridding Utilities in NCL supports this sort of grid (I mean directly interpolating in spherical coordinate with periodic boundary). Another package for spherical interpolation is SCRIP.
Mohammad Abouali
Mohammad Abouali on 29 Oct 2014
I got your message. Let me make an example and I get back to you.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!