3D vector plot having starting and ending points
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello, I'm currently a starter in 3d plotting in MATLAB and i was confused when I was trying to do a 3d vector plotting. I have the starting and ending point of a vector and I tried plotting it in 3D space, however, somehow the plot doesn't seems to be correct since the ending point of the vector doesn't seems to be the same point as given. I just want to ask how 3D vectors are defined and how should they be plotted based on starting and ending points especially when the starting point is not the origin. It would be helpful if some sample codes and examples are provided.
댓글 수: 0
답변 (1개)
Star Strider
2024년 9월 21일
It would help to have your code.
The way I usually plot vectors in 3-space —
x = [1 2];
y = [3 4];
z = [2 8];
figure
plot3(x, y, z)
grid on
axis('padded')
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Plotted Vector')
figure
plot3(x, y, z)
hold on
stem3(x, y, z, 'sr--', 'filled')
hold off
grid on
axis('padded')
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Plotted Vector With ‘stem3’ Enhancement')
.
댓글 수: 2
Star Strider
2024년 9월 22일
편집: Star Strider
2024년 9월 22일
Calculating them can be done any of severel ways, depending on what you want to do. There seems to be only one way to plot them in MATLAB, and I demonstrated that here.
Plotting them as a vector filed (uwing quiver or quiver3) requires an additional set of arguments, those being the derivatives of the vector components (calculated with the gradient function here) —
x = [1 2];
y = [3 4];
z = [2 8];
gx = gradient(x);
gy = gradient(y);
gz = gradient(z);
figure
quiver3(x, y, z, gx, gy, gz)
grid on
axis('padded')
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Plotted Vector')
figure
quiver3(x, y, z, gx, gy, gz)
hold on
stem3(x, y, z, 'sr--', 'filled')
hold off
grid on
axis('padded')
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Plotted Vector With ‘stem3’ Enhancement')
This works in MATLAB Online, however I’m getting some sort of weird ‘Authentication failed’ error, so I can’t run it here. I guess MathWorks must be doinig site maiintenance.
EDIT — (22 Sep 2024 at 16:13)
It works this morning, so I ran my previously-posted (and unchanged) code
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!