我目前面临标题中提到的问题。 如果我只想拥有 3 个单独的点并将它们记录为在 matlab 中具有 3 个坐标的点很容易,如下所示
A=[0 0 1];%coordinates of Q1
B=[0 0 -1];%coordinates of Q2
C=[0 1 0];%coordinates of Q3
因此,描述了A(0,0,1)、B(0,0,-1)、C(0,1,0)的坐标。在进一步的计算中,我可以使用坐标并进行如下计算:
R1=A-B; %vector from Q2 to Q1
R2=A-C; %vector from Q3 to Q1
R3=C-B; %vector from Q2 to Q3
但是,如果我想生成很多点,比如随机生成 100 个点,我上面写的方式是愚蠢的。而且我也想像以前一样使用坐标来做,因为它更方便。下面是我试过的方法。
% random distributed points
x = rand(Number_of_Points, 1);
y = rand(Number_of_Points, 1);
z = x.^2 + y.^2;
Points = [x(:) y(:) z(:)];
但是它只记录了所有点的3个坐标我不能像以前那样单独记录它们。我想通过使用 Points(1)-Points(2)
计算矢量 有谁知道如何做吗?
最佳答案
你只需要使用下标索引而不是线性索引:
Points(1,:) - Points(2,:)
否则,如果你想要欧氏距离,你可以这样做
sqrt(sum((Points(1,:) - Points(2,:)).^2))
或者让自己成为一个匿名函数:
PointsDistance = @(a,b)(sqrt(sum((Points(a,:) - Points(b,:)).^2)))
现在你可以调用
PointsDistance(1,2)
关于matlab - 将 3d 坐标存储在点列表中 Matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26157579/