Matlab的:我有一个3D图两点,我想他们用线连接 [英] Matlab: I have two points in a 3D plot and i want to connect them with a line
问题描述
我有一个3D图和两个点坐标A(0,0,0)和B(13,-11,19)。我只是想绘制可见的线连接这两个点......我想plot3(0,0,0,13,-11,19)和其他的东西,但一切我尝试彻底失败。
I have a 3D plot and two points coordinates A(0,0,0) and B(13,-11,19). I just want to plot a visible line connecting this two points ... I tried plot3(0,0,0, 13,-11,19) and other stuff but everything i tried failed miserably.
推荐答案
具体方法如下:
% Your two points
P1 = [0,0,0];
P2 = [13,-11,19];
% Their vertial concatenation is what you want
pts = [P1; P2];
% Because that's what line() wants to see
line(pts(:,1), pts(:,2), pts(:,3))
% Alternatively, you could use plot3:
plot3(pts(:,1), pts(:,2), pts(:,3))
诚然,这似乎有点违反直觉在第一,但在长远来看,这将是有意义的。
Admittedly, this might seem a bit counter-intuitive at first, but in the long run it'll make sense.
如果你读 DOC情节
或 DOC行
,你会发现每一个希望的集 X ,是
和以Z
资料>分别。也就是说,使用
If you read doc plot
or doc line
, you'll see that each expects sets of x
, y
and z
data, respectively. That is, using
plot3(X,Y,Z)
与 X
,是
和以Z
部分矩阵, plot3
将画一条线从第一的三重的( X(1)Y(1)Z(1)
)的第二个三线( X(2)Y(2)Z(2)
)等 - 同样为行
。
with X
, Y
and Z
some matrices, plot3
will draw a line from the first triplet (X(1) Y(1) Z(1)
) to the second triplet (X(2) Y(2) Z(2)
) and so on -- same for line
.
这篇关于Matlab的:我有一个3D图两点,我想他们用线连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!