Draw Triangle using quiver3 command in Matlab

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.

 採用された回答

Star Strider
Star Strider 2018 年 2 月 28 日
編集済み: Star Strider 2018 年 2 月 28 日

1 投票

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 件のコメント

iam
iam 2018 年 3 月 2 日
Thanks for your response. These vectors forms vertices of right angled triangle but the image does not show any right angle.
Star Strider
Star Strider 2018 年 3 月 2 日
My pleasure.
It does. You just have to rotate the plot to see it distinctly as a right triangle. I originally rotated it to show the vectors in 3-space, since that is what you apparently wanted, by specifying it as a 3-space triangle.
Change the view call to:
view(90, 0)
This depicts it along the x-axis, so only the y- and z-axes are visible.
If my Answer helped you solve your problem, please Accept it!
iam
iam 2018 年 3 月 3 日
Thanks. I really appreciate your help.
Star Strider
Star Strider 2018 年 3 月 3 日
As always, my pleasure.
Gavin Seddon
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
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 件)

カテゴリ

製品

質問済み:

iam
2018 年 2 月 28 日

コメント済み:

2018 年 3 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by