I want to plane fit my sperical data points.
조회 수: 5 (최근 30일)
이전 댓글 표시

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에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!