How can I change a spherical 1D into cartesian 3D?
Afficher commentaires plus anciens
Hello I have a matlab problem I need some guidance on. I solved the diffusion equation with a reaction term using the so called finite difference method. If you're not familiar with this, don't worry. It basically gives me an answer (concentration, C) which varies in space and time. My solution right now is a 1D in radius because I am assuming a symmetric profile around a center. Long story short, I have C in a 101X10000 array. The 101 is for the incremental radius (dr) and 10000 for incremental time (dt). I want to now change this into a 3D cartesian space such that each point in the space has a value of C corresponding to its equivalent radial location. I also want to capture the time domain somehow, and visualize the whole thing in an animation. I don't know how to do this and was hoping for some guidance on how to proceed. Just a sentence or a line of code to guide me may suffice.
Thanks in advance!
Réponses (1)
Star Strider
le 18 Mai 2016
0 votes
You emailed me about this, so I will at least follow up. The problem with your data is that you have incremental radius data and time data, but it’s not obvious to me (and apparently to everyone else) how you want this represented in polar or spherical coordinates.
See the documentation for the cart2pol and cart2sph functions, and experiment with them to see how you want to implement them with your data. You know your data better than we do, and you know how best you want them transformed.
8 commentaires
Katie Ciston
le 18 Mai 2016
Star Strider
le 18 Mai 2016
The reverse is (probably) as easy as what I described. See the pol2cart and sph2cart functions.
I don’t understand your array. That’s the reason I find it difficult to provide anything specific.
Katie Ciston
le 18 Mai 2016
Star Strider
le 18 Mai 2016
To use sph2cart and the others, you have to have your data in terms of the azimuth and elevation angles, and the radial distance. My guess is that you want to plot your data as distance and time in 3D space. It doesn’t seem to me that your data are in that form at present. You will likely need to transform them into a form the functions can work with.
I would first just plot your data using the mesh function:
figure(1)
meshc(C)
grid on
to see what it looks like. That will give you some idea of what you’re working with. If you want to save your ‘C’ matrix as a .mat file and upload it as an attachment to your original post (click on ‘Edit’ and then click on the ‘paperclip’ icon and be sure to do both the ‘Choose file’ and ‘Attach file’ steps).
That will give me the opportunity to experiment with it. I can’t promise results (what you want to do may not be possible), but I will see if I can transform it.
Katie Ciston
le 18 Mai 2016
Star Strider
le 18 Mai 2016
You can get a better idea of your data by taking the log of it:
D = load('Katie Ciston Concentration.mat');
Mtx = D.uu1;
Range = [min(Mtx(:)) max(Mtx(:))];
figure(1)
meshc(Mtx+1)
grid on
set(gca, 'ZScale','log')
The minimum of your data are 0, so it’s necessary to add 1 before taking the log. I’m still not quite certain how you want to transform it, since I don’t have a good idea of what you want to do. You also have two ‘peaks’ in your data, and I’m not certain how to interpret them.
Katie Ciston
le 20 Mai 2016
Star Strider
le 20 Mai 2016
My pleasure.
I’m still not certain of what you want to do. For a spherical transformation, you need to define your array in terms of two angles and a radius, and I don’t understand how to do that with your data.
Your data are a radial distance and time, but to work with the 2D pol2cart function, time then becomes the angle. That’s easily enough done (scale your time dimension by 2*pi/max(time)), but is that what you want to do?
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!