Matlab 测试点是否位于4D中的2D拟合平面上
假设在R^4中有3+个共面点,但没有共线点。为了找到它们都位于其中的二维平面(不是超平面),我使用了MatlabCentral的以下平面拟合算法:Matlab 测试点是否位于4D中的2D拟合平面上,matlab,vector,geometry,linear-algebra,Matlab,Vector,Geometry,Linear Algebra,假设在R^4中有3+个共面点,但没有共线点。为了找到它们都位于其中的二维平面(不是超平面),我使用了MatlabCentral的以下平面拟合算法: function [n,V,p] = affine_fit(X) % Computes the plane that fits best (least square of the normal distance % to the plane) a set of sample points. % INPUTS: % X:
function [n,V,p] = affine_fit(X)
% Computes the plane that fits best (least square of the normal distance
% to the plane) a set of sample points.
% INPUTS:
% X: a N by 3 matrix where each line is a sample point
%OUTPUTS:
%n : a unit (column) vector normal to the plane
%V : a 3 by 2 matrix. The columns of V form an orthonormal basis of the plane
%p : a point belonging to the plane
%NB: this code actually works in any dimension (2,3,4,...)
%Author: Adrien Leygue
%Date: August 30 2013
% the mean of the samples belongs to the plane
p = mean(X,1);
% The samples are reduced:
R = bsxfun(@minus,X,p);
% Computation of the principal directions of the samples cloud
[V,D] = eig(R'*R);
% Extract the output from the eigenvectors
n = V(:,1);
V = V(:,2:end);
end
我在比规定更高的维度中使用了该算法,因此X是一个4x4矩阵,它在4个坐标维度中包含4个点。生成的输出是这样的
[n,V,p] = affine_fit(X);
n = -0.0252
-0.0112
0.9151
-0.4024
V = 0.9129 -0.3475 0.2126
0.3216 0.2954 -0.8995
0.1249 0.3532 0.1493
0.2180 0.8168 0.3512
p = -0.9125 1.0526 0.2325 -0.0621
我现在想做的是找出我选择的其他点是否也是平面的一部分。考虑到上面的信息,我确信这是相当容易的,但在这一点上,我只知道我需要两个线性方程来描述4D中的2D平面或两个变量的参数方程。我可以在理论上设置它们,但是编写代码是有问题的。也许有一种更直接的方法可以在matlab中进行测试?您可以使用matlab函数(参见示例)。例如,可以确定平面的基础、平面的法向量和平面上的点m,如下所示:
coeff = pca(X);
basis = coeff(:,1:2);
normals = coeff(:,3:4);
m = mean(X);
要检查点p是否位于该平面上,只需使用验证
m-p
与平面上的法向量正交(点积等于零)即可。啊,太好了,谢谢!所以,m-p必须与两条法线中的每一条正交,对吗?如果X是一个由4个点组成的4x4矩阵,而coeff=pca(X)只给出了一个3x4矩阵,我能得出其中两个点是共线的结论吗?我相信你能。通过验证X的秩,始终可以检查点是否共线。