假设我在R ^ 4中有3个共面但不是共线点。为了找到它们都位于其中的2D平面(不是超平面),我使用了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: 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中有一种更简单的方法来测试它?