How to plot vectors pointing outwards from origin in a 3D matrix?

5 visualizaciones (últimos 30 días)
Something similar to the picture below. An origin point is specified and vectors are plotted outwards.
I need it in the format of three 3D matrices that each contain the component of the vector at the position. (Hx, Hy, Hz).
quiver3(X,Y,Z,Hx,Hy,Hz), ideally would plot something like the image below. (X,Y,Z are the positions, and Hx,Hy,Hz are vector components)

Respuesta aceptada

GreenEye
GreenEye el 24 de Feb. de 2021
Editada: GreenEye el 24 de Feb. de 2021
To anyone from the future, I answered my own question, as is often the case...
Using the spherical coordinate system
n = 32;
nc = round((n+1)/2);
vec = (1:n)-nc;
[x,y,z] = meshgrid(vec);
r = sqrt(x.^2 + y.^2 + z.^2);
psi = atan2(y,x);
theta = acos(z ./ r);
theta(isnan(theta)) = 0;
Mx = sin(theta).*cos(psi);
My = sin(theta).*sin(psi);
Mz = cos(theta);
quiver3(x,y,z,Mx,My,Mz)

Más respuestas (1)

Shadaab Siddiqie
Shadaab Siddiqie el 23 de Feb. de 2021
From my understanding you want to plot vectors in a cube with the axis pointing opposite to the center of the cube. Here is the code which might help you.
X = -3:3; Y = -3:3;Z= -3:3;
[X,Y,Z] = meshgrid(X,Y,Z);
quiver3(X,Y,Z,X,Y,Z)
In this case the position of the vector (line) is considered as the direction because of the problem statement.
  1 comentario
GreenEye
GreenEye el 24 de Feb. de 2021
Hi. This is close to what I want. Ideally there would be 3 matrices, each containing the vector component in them. For example, Hx(1,1,1) would contain the x component of the vector at the point (1,1,1). Hy(1,1,1) would contain the y component of the vector at the point (1,1,1). The vectors should have a length of 1.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by