Plotting Lines and Points in 3D
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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.
axis equal

DJ V
2024년 5월 21일
The man with all the answers!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
