CFD Online Logo CFD Online URL
Home > Forums > General Forums > Main CFD Forum

Visualization of Data in polar coordinates

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Search this Thread Display Modes
Old   December 2, 2002, 13:45
Default Visualization of Data in polar coordinates
Sujit Kirpekar
Posts: n/a

Can anyone help in converting a polar grid (r- and theta-) to X and Y for the purpose of plotting (The gird is unevenly spaced in r- and of course, evenly spaced in theta-)? MATLAB can do it using griddata() but cannot compute values close to the origin. MATLAB returns NaN (Not a Number) value for points near the origin.

Is there any visualization software (free, Unix based) that can read in 2D matrices with rows representing the r- direction and columns the theta- direction (and each element filled with value representing the function at that value of r- and theta-)?

Many Thanks

  Reply With Quote

Old   December 2, 2002, 15:59
Default Re: Visualization of Data in polar coordinates
Posts: n/a
Are you asking for simply:

x = r*cos(theta)

y = r*sin(theta)

or am I missing something?

  Reply With Quote

Old   December 2, 2002, 17:21
Default Re: Visualization of Data in polar coordinates
Sujit Kirpekar
Posts: n/a
Yes exactly, but its a little more complicated. Here's how:

I have a 2D (say N by N) matrix with where each element corresponds to the value of a function at certain r and certain theta.

By doing x = r*cos(theta) and y = r*sin(theta) I get a set of (N*N) x's and (N*N) y's because for each x there are N r's and N theta's. So now I have a N*N matrix for the x-coordinates and another N*N matrix for the y-coordinates. Clearly, values of x- and y- are unevenly spaced.

The question is .. how do I interpolate my data which is evaluated at these various N*N x's and y's to an evenly spaced grid? MATLAB needs an evenly spaced 2D grid to plot countours or surfaces.

I hope you understand the problem.

Thanks for your interest -- Sujit
  Reply With Quote

Old   December 3, 2002, 04:32
Default Re: Visualization of Data in polar coordinates
Posts: n/a
Matlab does not require evenly spaced data. You can simply calculated the x and y coordinates and use them directly in contour function.
  Reply With Quote

Old   December 3, 2002, 12:41
Default Re: Visualization of Data in polar coordinates
Sujit Kirpekar
Posts: n/a
Hi, thanks for your help. Indeed MATLAB can take in 2D matrices for X and Y that don't need to be evenly spaced.

I have another question: Would you know how to visualize 3D contour data? Plot surfaces of constant function value? I wrote something like this: but it dies (returns NaN) at the origin. Could someone show me a better way to do it?

Many Thanks,




start = cputime;

nz = 128;

nt = 128;

nx = 128;

zlen = 4.33121852439964;


%load r and theta collocation points.

load rData.dat;

load thetaData.dat;

ti = -4:.1:4;

[XI,YI] = meshgrid(ti,ti);

%clear ti;

for i=1:nz

for j=1:nt*2

x(i,j) = rData(i)*cos(thetaData(j));

y(i,j) = rData(i)*sin(thetaData(j));




%load up the 3D matrix for vorticity

%It is actually a 2D ascii file

load omegaZ_3D_001;

rawData = omegaZ_3D_001;

clear omegaZ_3D_001;

%rearrange the 2D ascii data into the 3D matrix it


for i=0:nx-1

temp = rawData((nz+1)*i+1nz+1)*(i+1),1:2*(nt+1));

data(:,:,i+1) = temp(:,;


clear temp, rawData; <font color = red> %convert vorticity from r- theta- to x- y-

%This is where griddata() returns NaN at the origin.

for k=1:nx

temp = data(1:nz,1:2*nt,k);

output(:,:,k) = griddata(x,y,temp,XI,YI, 'cubic');

now = cputime-start

end </font> clear temp


%Various ways to visualize.

%surf(XI,YI,output(:,:,64)), hold; grid on; view([30 65])

%shading flat; shading interp;

z = 0:zlen/nx:zlen;

z = (z(1:nx))';

x = (XI(1,)';

y = YI(:,1);

%output = smooth3(output);


%this produces contour lines in various slices

%this is probably the best!

%h = contourslice(x,y,z,output,[0],[0],[1:0.1:12]);

%axis([-3,3,-3,3,0,13]); daspect([1,1,1])

%camva(24); camproj perspective;



%set(gca,'Color','black','XColor','white','YColor' ,'whi te','ZColor','white')

%box on


%use this for solid and multicolored tubes

%note: for a good view 'output' must have positive vorticity

%if everything is red, make output = -output

p1 = patch(isosurface(x,y,z,output),'FaceColor','blue', 'Edge Color','none');

p2 = patch(isocaps(x,y,z,output),'FaceColor','interp',' EdgeC olor','none');



%if you want a hollow tube use this one:

%p = patch(isosurface(x,y,z,output));




view(3); axis vis3d;

axis([-4 4 -4 4 0 zlen])

camlight left; camlight; lighting phong;

timeItTook = cputime - start
  Reply With Quote


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Neumann Boundary Condition for Poisson Equation solution in Polar Coordinates prapanj Main CFD Forum 2 July 30, 2011 19:07
polar coordinates Joscha OpenFOAM 0 May 25, 2010 05:39
Polar coordinates in Fluent Ergys Rexhepi FLUENT 0 January 9, 2009 07:04
OpenFOAM native format data visualization and workflow zeliboba OpenFOAM Post-Processing 0 September 12, 2008 08:44
How to update polyPatchbs localPoints liu OpenFOAM Running, Solving & CFD 6 December 30, 2005 17:27

All times are GMT -4. The time now is 01:44.