Re: 2-d Interpolation from cartesian to polar coordinates
- From: "Michael Kleder" <mkleder@xxxxxxxxxxx>
- Date: Sun, 28 Aug 2005 12:25:09 -0400
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.
.
- References:
- 2-d Interpolation from cartesian to polar coordinates
- From: Kevin Gartz
- Re: 2-d Interpolation from cartesian to polar coordinates
- From: John D'Errico
- 2-d Interpolation from cartesian to polar coordinates
- Prev by Date: Re: GUI state
- Next by Date: help needed with the matlab code inside
- Previous by thread: Re: 2-d Interpolation from cartesian to polar coordinates
- Next by thread: including graphics(.eps) from Matlab in latex and Matlab v. 7
- Index(es):
Relevant Pages
|