【问题标题】:How to create a 3D plane from a scatter of data in Matlab如何从 Matlab 中的散点数据创建 3D 平面
【发布时间】:2016-09-27 22:17:43
【问题描述】:

目标 - 在 Matlab 中从散布的 XYZ 数据创建平面

说明: 正在寻找一种从大型数据集创建平面的方法。
该数据集是来自不完全平坦的表面的扫描测量数据,并且它不会与任何平面保持平坦,因此难以进行统计分析。

目标是找到一个最能代表大多数点的平面,然后将其与 XY 平面对齐,以便从中提取信息。

所附图片是数据图。颜色表示高度。注意:忽略小蓝点,这是我不需要担心的其他数据。


数据的结构:

数据以 N X 3 数组的形式出现

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

平面几乎是平的,但我需要“平均平面”与 XY 平面完全对齐,以考虑其他可能不像本例那样平的数据。

找到“平均平面”后,我会进行矩阵变换,通过找到平面与 XY、XZ 和 YZ 轴的角度来将其与轴对齐


我在搜索中也找到了我不寻找的东西:从 3 个点找到平面或使用 surf 或 delauny 从数据中找到“滚动”曲面图。

Example of plotted surface data - Image

【问题讨论】:

  • 你熟悉slice吗?
  • 我只是稍微研究了一下。它看起来会根据您提供的任何参数从数据中创建一个切片。不幸的是,困难的部分是找到那架飞机应该是什么。因为我需要自动化处理许多数据集的过程,所以我需要一种自动化的方法来找到穿过大部分数据的平面的 3D 旋转。
  • 好吧,我猜你得工作了。首先找出最佳平面(->优化问题),然后使用slice 沿该平面推断您的数据(->插值问题)。

标签: matlab 3d average data-analysis plane


【解决方案1】:

你试过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);

【讨论】:

  • acos 中的那些数量不就是planeNorm 的三个组成部分吗?
  • 是的,我只是想展示它背后的数学,以便 OP 可以使用通用平面
【解决方案2】:

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])

【讨论】:

    猜你喜欢
    • 2015-06-15
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    • 1970-01-01
    • 2018-06-24
    • 2018-12-17
    • 2018-06-13
    • 2017-09-15
    相关资源
    最近更新 更多