
Draw Triangle using quiver3 command in Matlab
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Star Strider
2018-2-28
编辑:Star Strider
2018-2-28
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.
6 个评论
Gavin Seddon
2018-3-21
Hello Star strider how do I change the position of the arrowhead so it is at the hypotenuse terminus? Thank you. GS.
Star Strider
2018-3-21
@Gavin Seddon — I do not understand what you are asking.
I encourage you to experiment with the code to get the result you want. In the second plot (link) the points are labeled, so you can follow them more easily.
The code with the labeled vertices is:
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
axis([0 10 0 5 -6 5])
text(abc(1:end-1,1), abc(1:end-1,2), abc(1:end-1,3), {'\bfa\rm','\bfb\rm','\bfc\rm'}, 'HorizontalAlignment','center', 'VerticalAlignment','bottom', 'Color','r', 'FontSize',14)
xlabel('X')
ylabel('Y')
zlabel('Z')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
