MATLAB Answers

Using streamline with vector field defiend on X,Y,Z converted from spherical coordinates

7 views (last 30 days)
Ron
Ron on 10 Jun 2013
I have a 3D coordinate system of R T P computed from ndgrid of r, theta, phi vectors. I then manually convert R T P into cartesean coordinates X,Y,Z to plot a 3D scalar value which is given in spherical coordinates on a nonuniform grid. So far so good.
Now, I also have a 3D vector field given in BR,BT,BP spherical data which I convert into cartesean BX, BY, BZ defined on the points X,Y,Z.
I can sucessfuly plot surfaces of the scalar field but when I try to use streamline() to make streamlines of BX,BY, and BZ they are all bunched up in a corner and ar enot correct. Looking at streamline() help file, it seems X,Y,Z must be in the meshgrid style form. Is this right? Is there any way to use streamline given an X,Y,Z converted form a meshgrid of R,T,P?
CODE: if true
%Get 3D cut cube coordinate matrices: [P_h T_h R_h] = ndgrid(pvec_h_cut,tvec_h_cut,rvec_h_cut);
%Convert coordinate matrices to Cartesean: X = R_h.*sin(T_h).*cos(P_h); Y = R_h.*sin(T_h).*sin(P_h); Z = R_h.*cos(T_h);
%Convert B-vectors to Cartesean: BX = sin(T_h(2:end-1,2:end-1,2:end-1)).*cos(P_h(2:end-1,2:end-1,2:end-1)).*BRcut + ... cos(T_h(2:end-1,2:end-1,2:end-1)).*cos(P_h(2:end-1,2:end-1,2:end-1)).*BTcut + ... -sin(P_h(2:end-1,2:end-1,2:end-1)).*BPcut; BY = sin(T_h(2:end-1,2:end-1,2:end-1)).*sin(P_h(2:end-1,2:end-1,2:end-1)).*BRcut + ... cos(T_h(2:end-1,2:end-1,2:end-1)).*sin(P_h(2:end-1,2:end-1,2:end-1)).*BTcut + ... cos(P_h(2:end-1,2:end-1,2:end-1)).*BPcut; BZ = cos(T_h(2:end-1,2:end-1,2:end-1)).*BRcut + ... -sin(T_h(2:end-1,2:end-1,2:end-1)).*BTcut;
h = streamline(X(2:end-1,2:end-1,2:end-1),... Y(2:end-1,2:end-1,2:end-1),... Z(2:end-1,2:end-1,2:end-1),... BX,BY,BZ,... X(2:fls_p:end-1,2:fls_t:end-1,2),... Y(2:fls_p:end-1,2:fls_t:end-1,2),... Z(2:fls_p:end-1,2:fls_t:end-1,2));
end

  0 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by