Plotting Lines and Points in 3D
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I need to learn how to plot lines and points in 3D. Can someone please provide an example in Matlab? Thank you.
採用された回答
Voss
2024 年 5 月 21 日
A = [1 -3 7];
B = [0 2 -6];
C = [0.5 -1 5];
% plot a line from A to B
v = [A; B];
plot3(v(:,1),v(:,2),v(:,3))
box on
grid on
xlabel('x')
ylabel('y')
zlabel('z')
% plot the point C
hold on
plot3(C(1),C(2),C(3),'o')

8 件のコメント
Thank you for troubling to answer: I come up with the following trying to create a drawing, but two of the lines aren't being shown. The ones that go to -1 on the Y axis. Can this be fixed to include the -1 on the Y axis? Is there a way to control the magnitude of the box that is being turned on? Is there a way to control the dimensions of the box that is turned on? Thanks.
A1 = [0 0 0];
A2 = [1 1 2];
A3 = [-1 1 2];
A4 = [1 -1 2];
A5 = [-1 -1 2];
% plot a line from A1 to AN
v = [A1; A2];
plot3(v(:,1),v(:,2),v(:,3))
box on
hold on
v = [A1; A3];
plot3(v(:,1),v(:,2),v(:,3))
hold on
v = [A1, A4];
plot3(v(:,1),v(:,2),v(:,3))
hold on
v = [A1, A5];
plot3(v(:,1),v(:,2),v(:,3))
hold on
box on
grid on
Voss
2024 年 5 月 21 日
You're welcome!
The problem with the plots involving A4 and A5 is that you're horizontally concatenating instead of vertically concatenating, which makes v 1x6 instead of 2x3. When v is 1x6, doing plot3(v(:,1),v(:,2),v(:,3)) plots a single point instead of two points with a line in between.
A1 = [0 0 0];
A2 = [1 1 2];
A3 = [-1 1 2];
A4 = [1 -1 2];
A5 = [-1 -1 2];
% plot a line from A1 to AN
v = [A1; A2];
plot3(v(:,1),v(:,2),v(:,3))
hold on
v = [A1; A3];
plot3(v(:,1),v(:,2),v(:,3))
v = [A1; A4];
% ^ semicolon (not comma)
plot3(v(:,1),v(:,2),v(:,3))
v = [A1; A5];
% ^ semicolon (not comma)
plot3(v(:,1),v(:,2),v(:,3))
box on
grid on
You can control the axes limits (and thus the box around the axes) using xlim, ylim, and zlim, e.g.:
ylim([-1 2])

DJ V
2024 年 5 月 21 日
Thank you very much!
Voss
2024 年 5 月 21 日
You're welcome! Any questions, let me know. Otherwise, please "Accept" this answer. Thanks!
DJ V
2024 年 5 月 21 日
Is there any command I can give to get MATLAB to draw this thing to scale? Thank you.
Voss
2024 年 5 月 21 日
axis equal

DJ V
2024 年 5 月 21 日
The man with all the answers!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
