Conversion from Cartesian X,Y,Z to domain-centric cylindrical coordinates

I just have a question on the conversion from Cartesian X,Y,Z to domain-centric cylindrical coordinates. I have a computed variable, an energy flux term, say F.
Currently, F is a function of x,y,z. Here, the x,y,and z are not lat-Lon values but are more like indices. For example, the grid has 480 grids in the X and Y direction with a spacing of 1km each. So I simply define X as 1000 to 480,000 in increments of 1000 (meters). Y and X are the same since the grid is uniform. I use actual Z values which are non-uniform.
What I’d like to do is to transform this variable, F into r,theta,z coordinates with reference to the domain center. What is the best way to do this in Matlab?

4 commentaires

Do you have a function for F, or just the data at the x,y,z grid points?
Well, I did have a function with which I am able to create the data for F as a function of x,y,z. For the present purpose, please assume that I do not want to change the function but only the data from x,y,z to r,theta,z.
Thanks for the response.
Sindar
Sindar le 24 Jan 2020
Modifié(e) : Sindar le 24 Jan 2020
An algorithm:
  • generate a cylindrical grid (decide whether you want r_max to include all xyz points, or to exclude any unknown points, or somewhere between)
  • transform this grid into Cartesian (x2=r*cos(theta), etc.)
  • interpolate F from your original grid to the new Cartesian grid (interp3)
  • you now have F2 at your new cylindrical grid
Thank you, while your algorithm will work, I am looking for a methodology that involves the least amount of interpolation. Is it possible to transform the current dataset (x,y,z) to corresponding values of r and theta - the sense of the radius should be outward from the domain center and the sense of theta must be anticlockwise about that center (Starting from theta = 0 at the East, Increasing Y - Decreasing X - Decreasing Y - Increasing X). So that each X,Y,Z has a corresponding r,theta,z and then I find a way to plot the slices or isosurfaces?

Connectez-vous pour commenter.

 Réponse acceptée

Sindar
Sindar le 24 Jan 2020
Modifié(e) : Sindar le 24 Jan 2020
% example data
X = 1000:1000:480000;
Y = X;
Z = sort(rand(size(X)));
Domain_Center = [mean(X([1 end])) mean(Y([1 end])) mean(Z([1 end]))]
% compute Cylindrical coordinates
[theta,rho,z] = cart2pol(X-Domain_Center(1),Y-Domain_Center(2),Z - Domain_Center(3));
% F = F

5 commentaires

Thank you! One correction that I must make (I should have been clear about this previously) is that the domain center is the same for all Z-levels. There is a central axis that goes through all the z levels at the center of x and y. Finally, I seek to understand if Matlab's [theta,r,z] = cart2pol(x,y,z) will do the job that you are describing. I am guessing that is a more efficient way to do this? This is a pretty data intensive approach and I am concerned about that.
saipb
saipb le 24 Jan 2020
Modifié(e) : saipb le 24 Jan 2020
Thanks for the edit. I still think that the domain center should not involve the mean in the Z direction. The data in Z direction will remain unchanged. It is only x and y that will get transformed to R and theta.
I wasn't sure what you meant by domain center so I chose a harder one to calculate. If you know what it is, then define that, e.g.:
Domain_Center = [mean(X([1 end])) mean(Y([1 end])) 0]
I'm not sure that cart2pol is actually faster (if you look at the algorithm, it's the same), but it is easier to read
Thank you very much. https://www.mathworks.com/help/matlab/ref/cart2pol.html informs me that the algorithm assumes that the origin is the center. Looks like by incorporating X-x(center) and Y - y(center), we solve this issue. Finally, 1. Where can I look at the algorithm for cart2pol that you mention in your comment? 2. At present, I use a combination of slice and isosurface to generate a 3D plot of F as a function of x,y,z. Once I convert to r,theta,z - is it possible to use slices and isosurfaces even then or are there other options?
slices and isosurfaces will treat your r,theta,z coordinates exactly like cartesian ones. For instance, visually, the slices will still be planes but they will be slices along r instead of x, etc.. I'd just try first and see what happens.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by