平面(ax+by+cz+d=0)への近似

3次元のランダムに散らばった点群データ(約1000点)から平面(ax+by+cz+d=0)への近似を行う方法を教えてください。

 Accepted Answer

michio
michio on 15 Dec 2016
Edited: michio on 15 Dec 2016

3 votes

ような例もあるようですが、Curve Fitting Toolbox の cftool を使用して、データを z = d + ax + by の形にフィッティングできるので、こちらでも用途に合うかもしれません。

4 Comments

ご回答ありがとうございます。 おかげで平面への近似を行うことができました。
追加で質問しても良いでしょうか。 この結果から係数を抜き出したいのですが、どのようなコードになるのでしょうか。 重ねてよろしくお願い致します。
以下、近似のコードになります
--
% 近似を作成します。
%
% '新規近似 1' に対するデータを近似:
% X 入力: plane01_x
% Y 入力: plane01_y
% Z 出力: plane01_z
% 出力:
% fitresult: 近似を表す fit オブジェクト。
% gof: 適合性情報をもつ構造体。
%
% 参考 FIT, CFIT, SFIT.
% MATLAB からの自動生成日: 16-Dec-2016 15:35:47
%%近似: '新規近似 1'。
[xData, yData, zData] = prepareSurfaceData( plane01_x, plane01_y, plane01_z );
% 近似タイプとオプションを設定します。
ft = fittype( 'poly11' );
% モデルをデータに近似します。
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
% データの近似をプロットします。
figure( 'Name', '新規近似 1' );
h = plot( fitresult, [xData, yData], zData );
legend( h, '新規近似 1', 'plane01_z vs. plane01_x, plane01_y', 'Location', 'NorthEast' );
% ラベル Axes
xlabel plane01_x
ylabel plane01_y
zlabel plane01_z
grid on
view( 32.1, 12.4 );
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
で fitresult という近似オブジェクトが作られておりますので、
coeffvalues(fitresult)
で係数が取り出せます。モデルの詳細を確認したい場合はコマンドウィンドウ上で
fitresult
と実行してみてください。係数を明示的に取得する場合にはそれぞれ
fitresult.p00
fitresult.p10
fitresult.p01
などと個別に取得することも可能です。
Ichiro Suzuki
Ichiro Suzuki on 18 Dec 2016
係数を抜き出す関数があったんですね。知りませんでした。
ありがとうございます。 無事解決しました。
コメントありがとうございます。回答の Accept もどうぞよろしくお願いします。
今回の近似モデルに限らず、クラスメソッド(関数)は下記 methods コマンドで一覧を確認できますので、どんな関数・機能があるか気になった場合にはヘルプページ上での検索でもよいですが、methods も試してみてください。
methods(fitresult)

Sign in to comment.

More Answers (1)

KSSV
KSSV on 15 Dec 2016
clc; clear all ;
% Ax + By + Cz + D = 0
% where the coefficients "A", "B", "C", and "D" are known values.
A = rand ; B = rand ; C = rand ; D = rand ; % considering some random values
%%Method 1
x = [1 -1 -1 1]; % Generate data for x vertices
y = [1 1 -1 -1]; % Generate data for y vertices
z = -1/C*(A*x + B*y + D); % Solve for z vertices data
patch(x, y, z);
%%method 2
[x y] = meshgrid(-1:0.1:1); % Generate x and y data
z = -1/C*(A*x + B*y + D); % Solve for z data
surf(x,y,z) %Plot the surface

2 Comments

Ichiro Suzuki
Ichiro Suzuki on 15 Dec 2016
Hi KSSV! I wanna know an approximate calculation for plane if u know it plese give me a hint!
thk
KSSV
KSSV on 15 Dec 2016
You have to be bit clear about your question.What do you mean by approximate calculation?

Sign in to comment.

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Asked:

on 15 Dec 2016

Commented:

on 18 Dec 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!