WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Radius von Kugel

 

newone

Gast


Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 04.07.2017, 09:55     Titel: Radius von Kugel
  Antworten mit Zitat      
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);
switch nargin  % n x 3 matrix
    case 1
        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 unique sphere.');
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));

if nargout > 2
   % calculate residuals
   residuals = radius - sqrt(sum(bsxfun(@minus,[x y z],center.').^2,2));
elseif nargout > 1
   % skip
else
    % plot sphere
    hold all;
   sphere_gd(6,radius,center);
    hold on;
end


Jan S
Moderator

Moderator


Beiträge: 11.057
Anmeldedatum: 08.07.10
Wohnort: Heidelberg
Version: 2009a, 2016b
     Beitrag Verfasst am: 05.07.2017, 15:36     Titel: Re: Radius von Kugel
  Antworten mit Zitat      
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.

Nein, ich denke nicht. Laut Code:
Code:
function [center,radius,residuals] = sphere_fit(x,y,z)

wird der Mittelpunkt, der Radius und die Residuen zurückgegeben. Wenn Du alle 3 Outputs abfragst, solltest Du sie auch erhalten:
Code:
[center,radius,residuals] = sphere_fit(x,y,z)

Gruß, Jan
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

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
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

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.