MATLAB: Draw Triangle using quiver3 command in Matlab

3d plotsfigureMATLABplotting

Following are the position vectors that form vertices of a right angled triangle, a=[2 3 4], b=[6 2 -5], c=[8 1 -4]. I want to plot triangle using quiver3 command in Matlab. Any help will be appreciated. Thanks.

Best Answer

Try this:
a=[2 3 4];
b=[6 2 -5];
c=[8 1 -4];
abc = [a; b; c; a];
dabc = diff([abc; a]);
figure(1)
plot3(abc(:,1), abc(:,2), abc(:,3), 'pg', 'MarkerSize',15, 'MArkerFaceColor','g')
hold on
quiver3(abc(:,1), abc(:,2), abc(:,3), dabc(:,1), dabc(:,2), dabc(:,3), 0, 'LineWidth',2)
hold off
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
view(150, 40)
Experiment to get the result you want. I do not know how well this will generalise to other shapes.
EDIT Improved efficiency of the ‘dabc’ calculation.