I want to plane fit my sperical data points.
2 ビュー (過去 30 日間)
古いコメントを表示
Chiel van Wanrooij
2022 年 12 月 20 日
コメント済み: Chiel van Wanrooij
2022 年 12 月 20 日
I want to correct this data with the radius, so that it creates a plane. The radius is known due measurements.
Thank you in advance.
0 件のコメント
採用された回答
Bora Eryilmaz
2022 年 12 月 20 日
編集済み: Bora Eryilmaz
2022 年 12 月 20 日
Assuming a spherical surface with unknown origin (and perhaps radius), you can run an optimization algorithm to estimate the model parameters (origin, etc.) and subtract the location of the points on the surface of the sphere from your data. That would give you, roughly, a plane-like view of your data at a distance equal to the radius of the sphere.
A better planar view might be to actually project the data into an r-theta-z plane, but this would require a more complicated algorithm.
% "Unknown" model parameters.
x0 = 45;
y0 = 30;
z0 = -198;
r = 200.0;
% Construct the data surface
[X,Y] = meshgrid(0:1:100, 0:1:60);
Z = sqrt((r+randn(size(X))).^2 - (X-x0).^2 - (Y-y0).^2) + z0;
surf(X,Y,Z)
% Estimate model parameters x0, y0, z0, and r.
% You can remove "r" from the estimation if it is already known.
P0 = [30, 30, -30, 10];
options = optimset('MaxFunEvals', 2000);
P = fminsearch(@(p) fcn(p,X,Y,Z), P0, options)
% Project into the plane at distance r.
x0 = P(1);
y0 = P(2);
z0 = P(3);
r = P(4);
Zplane = Z - sqrt(r^2 - (X-x0).^2 - (Y-y0).^2) - z0;
surf(X,Y,Zplane)
function cost = fcn(p, X, Y, Z)
x0 = p(1);
y0 = p(2);
z0 = p(3);
r = p(4);
z = sqrt(r^2 - (X-x0).^2 - (Y-y0).^2) + z0;
cost = norm(z-Z, 2); % Least squares cost.
end
3 件のコメント
Bora Eryilmaz
2022 年 12 月 20 日
Yes, xco and yco need to be the same size for this to work. You may need to use ngrid() or meshgrid() commands to convert your data into the meshgrid format: https://www.mathworks.com/help/matlab/ref/meshgrid.html#mw_6ae7effe-9402-4974-b1a6-0391eba290d8.
その他の回答 (1 件)
Matt J
2022 年 12 月 20 日
You can use sphericalFit() from this FEX download
to fit a sphere to your points (non-iteratively). This does not currently allow you to constrain the radius to a known value, however, if that is essential, it would at least give you a pretty good initial guess of (x0,y0,z0) for the iterative optimization proposed by @Bora Eryilmaz.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Frequently-used Algorithms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!