필터 지우기
필터 지우기

I want to plane fit my sperical data points.

조회 수: 6 (최근 30일)
Chiel van Wanrooij
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.

채택된 답변

Bora Eryilmaz
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)
P = 1×4
44.1685 29.7778 -200.0555 201.9682
% 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
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.
Chiel van Wanrooij
Chiel van Wanrooij 2022년 12월 20일
Thank you for your help. I appreciate it.

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

추가 답변 (1개)

Matt J
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.

카테고리

Help CenterFile Exchange에서 Least Squares에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by