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

 채택된 답변

michio
michio 2016년 12월 15일
편집: michio 2016년 12월 15일

3 개 추천

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

댓글 수: 4

Ichiro Suzuki
Ichiro Suzuki 2016년 12월 16일
ご回答ありがとうございます。 おかげで平面への近似を行うことができました。
追加で質問しても良いでしょうか。 この結果から係数を抜き出したいのですが、どのようなコードになるのでしょうか。 重ねてよろしくお願い致します。
以下、近似のコードになります
--
% 近似を作成します。
%
% '新規近似 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 );
michio
michio 2016년 12월 16일
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
fitresult という近似オブジェクトが作られておりますので、
coeffvalues(fitresult)
で係数が取り出せます。モデルの詳細を確認したい場合はコマンドウィンドウ上で
fitresult
と実行してみてください。係数を明示的に取得する場合にはそれぞれ
fitresult.p00
fitresult.p10
fitresult.p01
などと個別に取得することも可能です。
Ichiro Suzuki
Ichiro Suzuki 2016년 12월 18일
係数を抜き出す関数があったんですね。知りませんでした。
ありがとうございます。 無事解決しました。
michio
michio 2016년 12월 18일
コメントありがとうございます。回答の Accept もどうぞよろしくお願いします。
今回の近似モデルに限らず、クラスメソッド(関数)は下記 methods コマンドで一覧を確認できますので、どんな関数・機能があるか気になった場合にはヘルプページ上での検索でもよいですが、methods も試してみてください。
methods(fitresult)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2016년 12월 15일

2 개 추천

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

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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

질문:

2016년 12월 15일

댓글:

2016년 12월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by