3D vector plot having starting and ending points
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Star Strider
am 21 Sep. 2024
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 Kommentare
Star Strider
am 22 Sep. 2024
Bearbeitet: Star Strider
am 22 Sep. 2024
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
.
Siehe auch
Kategorien
Mehr zu Vector Fields finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!