30 views (last 30 days)

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?

Sindar
on 24 Jan 2020 at 18:43

Edited: Sindar
on 24 Jan 2020 at 18:50

% 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

Sindar
on 24 Jan 2020 at 19:08

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

Sindar
on 24 Jan 2020 at 19:33

The algorithm is on the documentation page https://www.mathworks.com/help/matlab/ref/cart2pol.html#bu5h1tr-1

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.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501843-conversion-from-cartesian-x-y-z-to-domain-centric-cylindrical-coordinates#comment_789717

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501843-conversion-from-cartesian-x-y-z-to-domain-centric-cylindrical-coordinates#comment_789717

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501843-conversion-from-cartesian-x-y-z-to-domain-centric-cylindrical-coordinates#comment_789720

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501843-conversion-from-cartesian-x-y-z-to-domain-centric-cylindrical-coordinates#comment_789720

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501843-conversion-from-cartesian-x-y-z-to-domain-centric-cylindrical-coordinates#comment_789722

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501843-conversion-from-cartesian-x-y-z-to-domain-centric-cylindrical-coordinates#comment_789722

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501843-conversion-from-cartesian-x-y-z-to-domain-centric-cylindrical-coordinates#comment_789726

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501843-conversion-from-cartesian-x-y-z-to-domain-centric-cylindrical-coordinates#comment_789726

Sign in to comment.