Visualization of Data in polar coordinates
Hi,
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 Sujit 
Re: Visualization of Data in polar coordinates
Are you asking for simply:
x = r*cos(theta) y = r*sin(theta) or am I missing something? 
Re: Visualization of Data in polar coordinates
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 xcoordinates and another N*N matrix for the ycoordinates. 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 
Re: Visualization of Data in polar coordinates
Matlab does not require evenly spaced data. You can simply calculated the x and y coordinates and use them directly in contour function.

Re: Visualization of Data in polar coordinates
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, Sujit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear 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)); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %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 %represents. for i=0:nx1 temp = rawData((nz+1)*i+1:(nz+1)*(i+1),1:2*(nt+1)); data(:,:,i+1) = temp(:,:); end 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 = cputimestart 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; %campos([20,6,25]) %set(gcf,'Color',[.5,.5,.5],'Renderer','zbuffer') %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'); isonormals(x,y,z,output,p1); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %if you want a hollow tube use this one: %p = patch(isosurface(x,y,z,output)); %isonormals(x,y,z,output,p) %set(p,'FaceColor','red','EdgeColor','none'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% view(3); axis vis3d; axis([4 4 4 4 0 zlen]) camlight left; camlight; lighting phong; timeItTook = cputime  start 
All times are GMT 4. The time now is 13:30. 