The HMC5883 calibration
no vote
function a = fitellipse(XY) % FITELLIPSE Least-squares fit of ellipse to 2D points. % A = FITELLIPSE(XY) returns the parameters of the best-fit % ellipse to 2D points XY. % The returned vector A contains the center, radii, and orientation % of the ellipse, stored as (Cx, Cy, Rx, Ry) % % Example: Run fitellipse without any arguments to get a demo if nargin == 0 % Create an ellipse t = linspace(0,2); Rx = 300 Ry = 200 Cx = 250 Cy = 150 Rotation = .4 % Radians x = Rx * cos(t); y = Ry * sin(t); nx = x*cos(Rotation)-y*sin(Rotation) + Cx; ny = x*sin(Rotation)+y*cos(Rotation) + Cy; % Draw it plot(nx,ny,\'o\'); % Fit it fitellipse(nx,ny) % Note it returns (Rotation - pi/2) and swapped radii, this is fine. return end % normalize data X=XY(:,1); Y=XY(:,2); mx = mean(X);