Re: 2-d Interpolation from cartesian to polar coordinates



Hello Kevin,

It sounds like, for the problem you have already solved, that you
have a function (or dataset) of the form
z=f(r,theta), and you've computed or obtained the z values for some
set of (r,theta) coordinates. I suspect you then defined a grid of
(x,y) coordinates and sought the z values for them. It sounds like
you used something like the following, where for example your chosen
x and y coordinates go from -5 to +5:

[x,y]=ndgrid(-5:.1:5,-5:.1:5);
zcart=griddata(r.*cos(theta),r.*sin(theta),z,x,y);

Initially, one might suppose that the following might solve the
inverse problem, where for example you already have z=f(x,y) and you
choose r to run from 0 to 5:

[r,th]=ndgrid(0,.1:5,-pi:pi/30:pi);
zpolar=griddata(sqrt(x.^2+y.^2),atan2(y,x),z,r,th);

However, a problems occurs. First, the zpolar values at coordinates
(r,-pi) and (r,+pi) may contain NaN values because there is no data
outside those angular boundaries from which to interpolate. (atan2
returns angles within
[-pi,pi].)

My suggestion is to create legitimate but redundant data "outside"
the angular range [-pi,pi] as a buffer zone for your interpolation.
For example, again starting with z=f(x,y) data where x and y both run
from -5 to 5:

[r,theta]=ndgrid(0:.1:5,-pi:pi/30:pi);
rdata=sqrt(x.^2+y.^2);
thdata=atan2(y,x);
rdata=[rdata(:);rdata(:);rdata(:)];
thdata=[thdata(:)-2*pi;thdata(:);thdata(:)+2*pi];
zpolar=griddata(rdata,thdata),z,r,theta);

Now, you should have the (r,theta) grid that you seek, together with
corresponding zpolar values.

I hope this helps. I don't have Matlab running on the machine I am
using at this moment, so I wasn't able to run the code to check for
mistakes. Hopefully bugs didn't creep in.

Cheers,
Mike
____________________

"Kevin Gartz" <kevin.gartz@xxxxxxxxxx> wrote:
Does anyone have a routine that can take data values
for points on regularly spaced cartesian grid and
interpolate them onto polar grid? I can go from polar to
rectangular with griddata but can't figure out how to go
from rectangular to polar.
.



Relevant Pages

  • polar type contour plot
    ... this grid is NOT rectangular but polar. ... the X is angles and the Y is range. ...
    (comp.soft-sys.matlab)
  • interpolate over a line function in matlab
    ... I have the outline of a pond, and I have assigned a rectangular ... I need to interpolate some depth data to this grid, except, I dont ... certain lines to interpolate across, so I can better follow my topography.. ...
    (comp.soft-sys.matlab)
  • 2-d Interpolation from cartesian to polar coordinates
    ... regualrly space cartesian grid and interpolate them onto polar grid? ... I can go from polar to rectangular with griddata but can't figure ...
    (comp.soft-sys.matlab)
  • Re: 2D interpolation from trinagular mesh to coarser (arbitrary) triangular
    ... Anybody any hints on where to find a routine that will known read x,y, ... value and interpolate on a new x_n, ... triangular grid. ... interpolate in the coarse grid using these data as input 2, ...
    (sci.math.num-analysis)
  • Re: Griddata too slow
    ... I have a large amount of 3D time dependent fluid flow data on a ... I am trying to interpolate this data on to a new 3D ... grid produced my meshgrid. ... and using griddata to find the interpolated values. ...
    (comp.soft-sys.matlab)