Adding a line to my plot3 of a plane

조회 수: 19 (최근 30일)
Haraldur Blöndal Kristjánsson
Haraldur Blöndal Kristjánsson 2020년 10월 21일
답변: Asad (Mehrzad) Khoddam 2020년 10월 21일
I am having a bit of a problem adding a line to my plot3 of a plane. This is my code for plotting just the plane
X = Final(1,:,:);
Y = Final(2,:,:);
Z = Final(3,:,:);
plot3(X,Y,Z,'o','color','b');
and it gives me this plot, which is what I want :
But then I wanted to add position vector to it - and as I understood it then its just a line from point b to projection of b onto the new plane (which is what is in the plot above).
So I just chose one of the original points as the p1 and p2 as the projection of it and then wanted to plot a line between them and add to the plot above. There I am having the trouble.
%Position vector
p1 = [200; -107; 0] %%original point
p2 = [201 ; -105; 3] %projected point
X = Final(1,:,:);
Y = Final(2,:,:);
Z = Final(3,:,:);
hold on
plot(p1,p2) %line plot
plot3(X,Y,Z,'o','color','b');
grid;
hold off
This is the result, but I was hoping for something like this:

답변 (1개)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 10월 21일
Two lines should be fixed:
1- coordinates of end points of the line
2- Using plot3
%Position vector
p1 = [200; -107; 0] %%original point
p2 = [201 ; -105; 3] %projected point
px=[100 , 101];
py=[-107, -105];
pz=[0,3];
X = Final(1,:,:);
Y = Final(2,:,:);
Z = Final(3,:,:);
hold on
plot3(px,py,pz) %line plot
plot3(X,Y,Z,'o','color','b');
grid;
hold off

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by