필터 지우기
필터 지우기

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 CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by