Slicing a 3D vector field (defined in spherical basis and converted to cartesian basis) to view only the xz-plane of the vector field

2 views (last 30 days)
Suppose we have a vector field defined over a spherical grid
Example code (simpler vector field than the one I'm actually dealing with) directly below just a general problem statement (actual code later)
I'd like to isolate planes instead of writing an entirely new script.
% Defining spherical grid, extract vectors, and transpose
c4 = 180*(pi^(-1));
n = 25;
rmin = 0.001;
rmax = 400;
phi = linspace(-pi,pi - ((n)^(-1))*2*pi,n);
theta = linspace(-0.5*pi,0.5*pi - ((n)^(-1))*2*pi,n);
r = linspace(rmin,rmax,n);
[Phi,Theta,R] = meshgrid(phi,theta,r);
SPM = [Phi(:),Theta(:),R(:)]; %Spherical Points from Mesh
SPMT = SPM'; %Spherical Points from Mesh Transpose
SPMD = c4*SPM; %Now in degrees
SPMDT = SPMD'; % Now in degrees
%first have to convert the entire position grid to cartesian
[X,Y,Z] = sph2cart(Phi,Theta,R);
CPFM = [X(:),Y(:),Z(:)]; %Cartesian Points from mesh
CPFMT = CPFM'; %Cartesian Points from mesh transposed
% Suppose we have a vector field
for i1 = 1:size(SPMT,2)
Fr(1,i1) = SPMT(3,i1);
end
Faz = zeros(size(Fr));
Fel = zeros(size(Fr));
Fspherical = vertcat(Faz,Fel,Fr);
% Convert to this spherical basis to cartesian
for i2 = 1:size(Fspherical,2)
FCartesian(:,i2) = sph2cartvec(Fspherical(:,i2),SPMDT(1,i2),SPMDT(2,i2));
end
% quiver3 plot
quiver3(CPFMT(1,:),CPFMT(2,:),CPFMT(3,:),Fspherical(1,:),Fspherical(2,:),Fspherical(3,:))
The actual vector field I'm working with is the Poynting vector field of a radiating electric dipole and the script is really long and would be much more difficult to decipher. So instead I contrived the simper vector field above. Hopefully any advice I get will transfer over to my script.
Thanks in Advanced.

Accepted Answer

darova
darova on 10 Feb 2020
Use griddata to create 3D matrix
Use slice to create a crossection

More Answers (0)

Categories

Find more on Computational Geometry in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!