Matlab:我在 3D 图中有两个点,我想用一条线将它们连接起来 [英] Matlab: I have two points in a 3D plot and i want to connect them with a line

查看:39
本文介绍了Matlab:我在 3D 图中有两个点,我想用一条线将它们连接起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 plotdoc line,您会看到每个都期望sets x, yz 数据,分别.也就是说,使用

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)

使用XYZ 一些矩阵,plot3 将从第一个triplet (X(1) Y(1) Z(1)) 到第二个三元组 (X(2) Y(2) Z(2)>) 等等 -- 与 line 相同.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆