簡體   English   中英

如何找到點到平面的最小距離

[英]How to find minimum distance from points to a plane

我有一個與點雲相交的平面,並希望在交點周圍一定距離處提取點。 在我的腳本中,我已經可以確定平面周圍的點,但不幸的是,也確定了與我的平面不相交的點,如下圖所示。 (紅色圓圈表示確定的點)

在此處輸入圖片說明

這是我的腳本中檢測點的部分。

p0 = [0 0 0];
p1 = [-74 -76.968 0];
p2 = [0 0 690.18];

n = cross(p0-p1,p0-p2);
n = n/norm(n);

FDIST = @(X,Y,Z) sum(n.*(p0-[X Y Z]));
D = arrayfun(FDIST,x,y,z,'uni',false);
D1 = cell2mat(D);
mindist = 0.65;                           
ind = abs(D1) < mindist;

x、y 和 z 分別是 114964x1 個向量。 由於交點都在第三象限,我試圖只考慮 x 和 y 向量中的負值。 但是我收到一個錯誤,即輸入參數不再具有相同的長度。

idx = x1<0;
cx = x1(idx);

idy = y1<0;
cy = y1(idy);

Error using arrayfun
All of the input arguments must be of the same size and shape.
Previous inputs had size 57966 in dimension 1. Input #3 has size
58204

我認為另一種方法可能是調整FDIST ,但是我不太擅長 MATLAB 的function handle ,因此沒有成功。 在此先感謝您的幫助。

我認為您應該使用以下內容對第三象限內的點進行子集

idx_neg = (x <=0 & y<=0);
x = x(idx_neg);
y = y(idx_neg);
z = z(idx_neg);

使得xyz的維度相等。

我將以下代碼與虛擬數據一起使用,該代碼運行時沒有任何錯誤。

clc;
clear;

% dummy points data for x, y, and z
x = randn(100,1);
y = randn(100,1);
z = randn(100,1);

p0 = [0 0 0];
p1 = [-74 -76.968 0];
p2 = [0 0 690.18];

n = cross(p0-p1,p0-p2);
n = n/norm(n);

% restrict to the third quadrant
idx_neg = (x <=0 & y<=0);
x = x(idx_neg);
y = y(idx_neg);
z = z(idx_neg);

FDIST = @(X,Y,Z) sum(n.*(p0-[X Y Z]));
D = arrayfun(FDIST,x,y,z,'uni',false);
D1 = cell2mat(D);
mindist = 0.65;                           
ind = abs(D1) < mindist;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM