フィルターのクリア

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

4 ビュー (過去 30 日間)
GreenEye
GreenEye 2021 年 2 月 20 日
編集済み: GreenEye 2021 年 2 月 24 日
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)

採用された回答

GreenEye
GreenEye 2021 年 2 月 24 日
編集済み: GreenEye 2021 年 2 月 24 日
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)

その他の回答 (1 件)

Shadaab Siddiqie
Shadaab Siddiqie 2021 年 2 月 23 日
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 件のコメント
GreenEye
GreenEye 2021 年 2 月 24 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by