簡體   English   中英

如何在Matlab中通過分散數據創建3D平面

[英]How to create a 3D plane from a scatter of data in Matlab

目標-在Matlab中根據XYZ數據的散點創建平面

描述:尋找一種從大型數據集創建平面的方法。
數據集是來自並非完全平坦的表面掃描的測量數據,並且它並非平坦於任何平面,因此使統計分析變得困難。

目的是找到一個最能代表大多數點的平面,然后將其與XY平面對齊,以便從中提取信息。

附帶的圖像是數據圖。 顏色表示高度。 注意:請忽略小的藍點,這是我無需擔心的其他數據。


數據的結構:

數據作為NX 3陣列輸入

  • X是第一列
  • Y是第二列
  • Z是第三列

該平面幾乎是平坦的,但是我需要將“平均平面”與XY平面精確對齊,以考慮其他數據,該數據可能不像本例那樣平坦。

找到“平均平面”后,我將進行矩陣變換以通過查找平面與XY,XZ和YZ軸所成的角度將其與軸對齊


在搜索中也發現了我不想要的東西:從3個點中找到一個平面,或者使用沖浪或勞拉尼從數據中找到“滾動”表面圖。

繪制表面數據的示例-圖像

您是否嘗試過fit

ft = fit([X, Y], Z,'poly11');
UnnormPlaneNorm = [ft.p10; ft.p01; -1];
planeNorm = UnnormPlaneNorm / norm(UnnormPlaneNorm);
angleXY = acos([0,0,1] * planeNorm);
angleXZ = acos([0,1,0] * planeNorm);
angleYZ = acos([1,0,0] * planeNorm);

4個步驟:

%1.計算數據中心

%2.從數據中減去中心

%3.使2D平面適合中心數據

%4.重新添加計算的中心

首先,我將生成一組位於平面中的隨機數據:

clear;close all;clc;

% Create a random set of data 
mag = 20;
N   = 1000;
A   = 2 * mag * ( rand( N, 3 ) - 0.5 );

% We want to make sure that the data lies in a plane, so let's reduce it
% with the svd
[ U, S, V ] = svd(A,'econ');
S(3,3)      = 0;
A           = U * S * V.';

% Now we are going to offset the plane from the origin by a random point 
p   = 100 * rand(1,3); 
A   = A + repmat( p, N, 1 );

% Make sure we have the dataset we want by viewing from different angles
figure 
subplot(1,3,1)
plot3(A(:,1),A(:,2),A(:,3),'.')
hold on
grid minor
view([1,1,1])
subplot(1,3,2)
plot3(A(:,1),A(:,2),A(:,3),'.')
hold on
grid minor
view([1,-1,1])
subplot(1,3,3)
plot3(A(:,1),A(:,2),A(:,3),'.')
hold on
grid minor
view([-1,1,1])

在此處輸入圖片說明 現在,此時,A中的數據完全位於平面中。 但是我們想要嘈雜的數據以確保算法能夠正常工作。 因此,讓我們添加噪聲:

% Now let's add some noise to our data 
B   = A + randn(size(A));

現在我們開始使飛機適應數據...

% 1. Compute the center of the data 
c   = mean(B);

% 2. Subtract off the mean from the data 
D   = B - repmat( c, N, 1 );

% 3. Fit a 2D plane to the centered data 
[ U, S, V ] = svd( D, 'econ' );
S(3,3)      = 0;
D           = U * S * V.';

% 4. Offset by the computed center
D   = D + repmat( c, N, 1 );

% 5. Visualize by comparing with the noisy data
figure
subplot(1,3,1)
plot3(B(:,1),B(:,2),B(:,3),'.')
hold on
plot3(D(:,1),D(:,2),D(:,3),'.')
grid minor
view([1,1,1])
subplot(1,3,2)
plot3(B(:,1),B(:,2),B(:,3),'.')
hold on
plot3(D(:,1),D(:,2),D(:,3),'.')
grid minor
view([1,-1,1])
subplot(1,3,3)
plot3(B(:,1),B(:,2),B(:,3),'.')
hold on
plot3(D(:,1),D(:,2),D(:,3),'.')
grid minor
view([-1,1,1])

在此處輸入圖片說明

暫無
暫無

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

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