I want to plane fit my sperical data points.
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Chiel van Wanrooij
il 20 Dic 2022
Commentato: Chiel van Wanrooij
il 20 Dic 2022

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 Commenti
Risposta accettata
Bora Eryilmaz
il 20 Dic 2022
Modificato: Bora Eryilmaz
il 20 Dic 2022
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 Commenti
Bora Eryilmaz
il 20 Dic 2022
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.
Più risposte (1)
Matt J
il 20 Dic 2022
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 Commenti
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

