Converting Polar Gridded Data to Cartesian Gridded Data

39 views (last 30 days)
I am building a temperature distribution solver for a project and currently have a gridded temperature distribution in cylidrical coordinates. (R, Theta, Z). By my understanding this allows me to retain the temperature distribution as a 3d matrix with no corrolation to the true size of the object the matrix is describing. This allows me to theoretically use the isosurface functions to plot the outer surface and thus any other surface for my cylinder. I am stuck trying to convert my polar data to cartesian and interpolating the values in cartesian coordinates that dont exist in polar coordinates. I expect I could use 'grid data' or 'gridded interpolant' but these functions dont do what I am expecting. I could also slice the grids of my polar gridded data and use pol2car(th,r,z) where z is the temperature value accross the 'slice' but this also does not work as expected. I am unfamiliar with all of the functions I have mentioned and thus dont know what matlab expects and an input or output nor the math within the function.
Here is an example of what I am trying to do
T_Dat_pol = zeros(N_r, N_theta, N_z); % number of descritized points in r, th, and z directions
for i = 1:1:N_r
T_Dat_pol(i, :, :) = i; % (r, th, z)
end
%convert to cartesian.
T_Dat_cart = zeros(N_r^2, N_r^2, N_z) % (x, y, z)
T_Dat_pol represents a cylinder where the temperature varies only in the radial direction. With my current solution architechture r = 1 is the outer diameter. I would need to convert this to cartesian coordinates of arbitrary dimensions where x = 1/2 length(x), y = 1/2 length(y) is the midpoint of the cylinder.

Accepted Answer

Griffin Sisk
Griffin Sisk on 26 Oct 2023
Moved: Voss on 27 Oct 2023
I ended up using scatteredinterpolant to do each "slice" of my temperature data. Then combined after the fact.
maybe there are more efficient ways but this worked for me.
VQT = zeros(N_r*N_theta, N_r*N_theta, N_z);
for z = 1:1:N_z
xar = zeros(N_r*N_theta, 1);
yar = zeros(N_r*N_theta, 1);
var = zeros(N_r*N_theta, 1);
tempx = linspace(-R,R,N_r*N_theta);
tempy = linspace(-R,R,N_r*N_theta);
[cartx,carty] = meshgrid(tempx,tempy);
i = 1;
for r = 1:1:N_r
for theta = 1:1:N_theta
x = (R-(r-1)*(R/N_r)) * cos((theta-1) * (2*pi/N_theta));
y = (R-(r-1)*(R/N_r)) * sin((theta-1) * (2*pi/N_theta));
%plot(x,y, Marker=".", MarkerSize=10, MarkerEdgeColor="blue")
%hold on
xar(i) = x;
yar(i) = y;
var(i) = Dat(r, theta, z);
i = i+1;
end
end
F = scatteredInterpolant(xar, yar, var);
F.Method = 'nearest';
Vq = F(cartx,carty);
VQT(:, :, z) = Vq;
end

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!