Verfasst am: 04.07.2017, 09:55
Titel: Radius von Kugel
Hallo,
habe einige xyz-Koordinaten gegeben. An diese möchte ich eine Kugeloberfläche anfitten. Hierbei bin ich auf diese Funktion gestoßen. Sie gibt mir 3 Werte aus. Das sind der x, y und z-Wert des Kugelmittelpunkts und plottet die Kugel. Mir fehlt noch die Radiusinformation. Wie kann ich mir diese ausgeben lassen?
Bin für jede Hilfe dankbar.
Code:
function[center,radius,residuals] = sphere_fit(x,y,z) % Fit a sphere to data using the least squares approach.
%
% Fits the equation of a sphere in Cartesian coordinates to a set of xyz % data points by solving the overdetermined system of normal equations, i.e. % x^2 + y^2 + z^2 + a*x + b*y + c*z + d = 0 % The least squares sphere has radius R = sqrt((a^2+b^2+c^2)/4-d) and % center coordinates (x,y,z) = (-a/2,-b/2,-c/2).
%
% Input arguments: % x,y,z: % Cartesian coordinates of noisy data points
%
% Output arguments: % center: % coordinates of the least-squares fit sphere center % radius: % least-squares fit sphere radius % residuals: % residuals in the radial direction
%
% Examples: % [center,radius,residuals] = shperefit(X) % [center,radius,residuals] = spherefit(x,y,z);
% Copyright 2010 Levente Hunyadi
narginchk(1,3);
n = size(x,1);
switchnargin% n x 3 matrix case1
validateattributes(x, {'numeric'}, {'2d','real','size',[n,3]});
z = x(:,3);
y = x(:,2);
x = x(:,1);
otherwise% three x,y,z vectors
validateattributes(x, {'numeric'}, {'real','vector'});
validateattributes(y, {'numeric'}, {'real','vector'});
validateattributes(z, {'numeric'}, {'real','vector'});
x = x(:); % force into columns
y = y(:);
z = z(:);
validateattributes(x, {'numeric'}, {'size',[n,1]});
validateattributes(y, {'numeric'}, {'size',[n,1]});
validateattributes(z, {'numeric'}, {'size',[n,1]});
end
% need four or more data points if n < 4 error('spherefit:InsufficientData', ...
'At least four points are required to fit a uniquesphere.');
end
% solve linear system of normal equations
A = [x, y, z, ones(size(x))];
b = -(x.^2 + y.^2 + z.^2);
a = A \ b;
% return center coordinates and sphere radius
center = -a(1:3)./2;
radius = realsqrt(sum(center.^2)-a(4));
Verfasst am: 05.07.2017, 15:36
Titel: Re: Radius von Kugel
Hallo newone,
Ich finde im Code den Vermerk: "Copyright 2010 Levente Hunyadi". Wurde das unter eine BSD, MIT oder CreativeCommons Lizenz veröffentlich. "Copyright" könnte ja auch beinhalten, dass eine Kopie im Netz nicht erlaubt ist. Sollte es z.B. aus dem FileExchange stammen, muss auch das Lizenz-File beigefügt sein.
Zitat:
Sie gibt mir 3 Werte aus. Das sind der x, y und z-Wert des Kugelmittelpunkts und plottet die Kugel.
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.