²é¿´: 4716  |  »Ø¸´: 9
µ±Ç°Ö»ÏÔʾÂú×ãÖ¸¶¨Ìõ¼þµÄ»ØÌû£¬µã»÷ÕâÀï²é¿´±¾»°ÌâµÄËùÓлØÌû

zhhhero

Í­³æ (³õÈëÎÄ̳)

[ÇóÖú] matllabÖпռäÔ²ÈçºÎÄâºÏ£¿

Çó´óÏÀ£¬°ï棬ÈçºÎÔÚmatlabÖÐ×îС¶þ³Ë·¨ÄâºÏ¿Õ¼äÔ²£¬Çó³öÔ²ÐÄ£¬°ë¾¶¡£×îºÃÓÐmatlab³ÌÐò£¬Ð»Ð»
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

» ±¾Ö÷ÌâÏà¹Ø¼ÛÖµÌùÍÆ¼ö£¬¶ÔÄúͬÑùÓаïÖú:

ѧµ½ÀÏ£¬»îµ½ÀÏ
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

zhhhero

Í­³æ (³õÈëÎÄ̳)

ÒýÓûØÌû:
2Â¥: Originally posted by change0618 at 2013-05-02 09:22:48
¿ÉÒÔÈ¥matlab AppÖÐÐÄÏÂÔØ


function    = circfit(x,y)
%
%    = circfit(x,y)
%
%   fits a circle  in x,y plane in a more accurate
%   (less prone to ill condition )
%  procedure than circfit2 ...

¶ÔÁË£¬ÎÒÊÇÓÐ10×é¿Õ¼äµãÈýÎ¬×ø±ê£¬ÏÖÔÚÏëÄâºÏ¿Õ¼äÔ²
ѧµ½ÀÏ£¬»îµ½ÀÏ
8Â¥2013-05-02 22:22:14
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
²é¿´È«²¿ 10 ¸ö»Ø´ð

change0618

Ìú¸Ëľ³æ (ÖøÃûдÊÖ)

·½ÕÉ´óʦ

¡¾´ð°¸¡¿Ó¦Öú»ØÌû

¡ï ¡ï
¸Ðл²ÎÓ룬ӦÖúÖ¸Êý +1
xiegangmai: ½ð±Ò+2, лл²ÎÓ룡 2013-05-02 23:10:37
¿ÉÒÔÈ¥matlab AppÖÐÐÄÏÂÔØ
CODE:
function   [xc,yc,R,a] = circfit(x,y)
%
%   [xc yx R] = circfit(x,y)
%
%   fits a circle  in x,y plane in a more accurate
%   (less prone to ill condition )
%  procedure than circfit2 but using more memory
%  x,y are column vector where (x(i),y(i)) is a measured point
%
%  result is center point (yc,xc) and radius R
%  an optional output is the vector of coeficient a
% describing the circle's equation
%
%   x^2+y^2+a(1)*x+a(2)*y+a(3)=0
%
%  By:  Izhak bucher 25/oct /1991,
    x=x(:); y=y(:);
   a=[x y ones(size(x))]\[-(x.^2+y.^2)];
   xc = -.5*a(1);
   yc = -.5*a(2);
   R  =  sqrt((a(1)^2+a(2)^2)/4-a(3));

CODE:
%try_circ_fit
%
% IB
%
% revival of a 13 years old code


  % Create data for a circle + noise
  
  th = linspace(0,2*pi,20)';
  R=1.1111111;
  sigma = R/10;
  x = R*cos(th)+randn(size(th))*sigma;
  y = R*sin(th)+randn(size(th))*sigma;
  
   plot(x,y,'o'), title(' measured points')
   pause(1)
   
   % reconstruct circle from data
   [xc,yc,Re,a] = circfit(x,y);
      xe = Re*cos(th)+xc; ye = Re*sin(th)+yc;
   
     plot(x,y,'o',[xe;xe(1)],[ye;ye(1)],'-.',R*cos(th),R*sin(th)),
     title(' measured fitted and true circles')
      legend('measured','fitted','true')
      text(xc-R*0.9,yc,sprintf('center (%g , %g );  R=%g',xc,yc,Re))
     xlabel x, ylabel y
     axis equal
  

CODE:
function [center,rad,v1n,v2nb] = circlefit3d(p1,p2,p3)
% circlefit3d: Compute center and radii of circles in 3d which are defined by three points on the circumference
% usage: [center,rad,v1,v2] = circlefit3d(p1,p2,p3)
%
% arguments: (input)
%  p1, p2, p3 - vectors of points (rowwise, size(p1) = [n 3])
%               describing the three corresponding points on the same circle.
%               p1, p2 and p3 must have the same length n.
%
% arguments: (output)
%  center - (nx3) matrix of center points for each triple of points in p1,  p2, p3
%
%  rad    - (nx1) vector of circle radii.
%           if there have been errors, radii is a negative scalar ( = error code)
%
%  v1, v2 - (nx3) perpendicular vectors inside circle plane
%
% Example usage:
%
%  (1)
%      p1 = rand(10,3);
%      p2 = rand(10,3);
%      p3 = rand(10,3);
%      [center, rad] = circlefit3d(p1,p2,p3);
%      % verification, result should be all (nearly) zero
%      result(:,1)=sqrt(sum((p1-center).^2,2))-rad;
%      result(:,2)=sqrt(sum((p2-center).^2,2))-rad;
%      result(:,3)=sqrt(sum((p3-center).^2,2))-rad;
%      if sum(sum(abs(result))) < 1e-12,
%       disp('All circles have been found correctly.');
%      else,
%       disp('There had been errors.');
%      end
%
%
% (2)
%       p1=rand(4,3);p2=rand(4,3);p3=rand(4,3);
%       [center,rad,v1,v2] = circlefit3d(p1,p2,p3);
%       plot3(p1(:,1),p1(:,2),p1(:,3),'bo');hold on;plot3(p2(:,1),p2(:,2),p2(:,3),'bo');plot3(p3(:,1),p3(:,2),p3(:,3),'bo');
%       for i=1:361,
%           a = i/180*pi;
%           x = center(:,1)+sin(a)*rad.*v1(:,1)+cos(a)*rad.*v2(:,1);
%           y = center(:,2)+sin(a)*rad.*v1(:,2)+cos(a)*rad.*v2(:,2);
%           z = center(:,3)+sin(a)*rad.*v1(:,3)+cos(a)*rad.*v2(:,3);
%           plot3(x,y,z,'r.');
%       end
%       axis equal;grid on;rotate3d on;
%
%
% Author: Johannes Korsawe
% E-mail: johannes.korsawe@volkswagen.de
% Release: 1.0
% Release date: 26/01/2012

% Default values
center = [];rad = 0;v1n=[];v2nb=[];

% check inputs
% check number of inputs
if nargin~=3,
    fprintf('??? Error using ==> cirlefit3d\nThree input matrices are needed.\n');rad = -1;return;
end
% check size of inputs
if size(p1,2)~=3 || size(p2,2)~=3 || size(p3,2)~=3,
    fprintf('??? Error using ==> cirlefit3d\nAll input matrices must have three columns.\n');rad = -2;return;
end
n = size(p1,1);
if size(p2,1)~=n || size(p3,1)~=n,
    fprintf('??? Error using ==> cirlefit3d\nAll input matrices must have the same number or rows.\n');rad = -3;return;
end
% more checks are to follow inside calculation

% Start calculation
% v1, v2 describe the vectors from p1 to p2 and p3, resp.
v1 = p2 - p1;v2 = p3 - p1;
% l1, l2 describe the lengths of those vectors
l1 = sqrt((v1(:,1).*v1(:,1)+v1(:,2).*v1(:,2)+v1(:,3).*v1(:,3)));
l2 = sqrt((v2(:,1).*v2(:,1)+v2(:,2).*v2(:,2)+v2(:,3).*v2(:,3)));
if find(l1==0) | find(l2==0), %#ok<OR2>
    fprintf('??? Error using ==> cirlefit3d\nCorresponding input points must not be identical.\n');rad = -4;return;
end
% v1n, v2n describe the normalized vectors v1 and v2
v1n = v1;for i=1:3, v1n(:,i) = v1n(:,i)./l1;end
v2n = v2;for i=1:3, v2n(:,i) = v2n(:,i)./l2;end
% nv describes the normal vector on the plane of the circle
nv = [v1n(:,2).*v2n(:,3) - v1n(:,3).*v2n(:,2) , v1n(:,3).*v2n(:,1) - v1n(:,1).*v2n(:,3) , v1n(:,1).*v2n(:,2) - v1n(:,2).*v2n(:,1)];
if find(sum(abs(nv),2)<1e-5),
    fprintf('??? Warning using ==> cirlefit3d\nSome corresponding input points are nearly collinear.\n');
end
% v2nb: orthogonalization of v2n against v1n
dotp = v2n(:,1).*v1n(:,1) + v2n(:,2).*v1n(:,2) + v2n(:,3).*v1n(:,3);
v2nb = v2n;for i=1:3,v2nb(:,i) = v2nb(:,i) - dotp.*v1n(:,i);end
% normalize v2nb
l2nb = sqrt((v2nb(:,1).*v2nb(:,1)+v2nb(:,2).*v2nb(:,2)+v2nb(:,3).*v2nb(:,3)));
for i=1:3, v2nb(:,i) = v2nb(:,i)./l2nb;end

% remark: the circle plane will now be discretized as follows
%
% origin: p1                    normal vector on plane: nv
% first coordinate vector: v1n  second coordinate vector: v2nb

% calculate 2d coordinates of points in each plane
% p1_2d = zeros(n,2); % set per construction
% p2_2d = zeros(n,2);p2_2d(:,1) = l1; % set per construction
p3_2d = zeros(n,2); % has to be calculated
for i = 1:3,
    p3_2d(:,1) = p3_2d(:,1) + v2(:,i).*v1n(:,i);
    p3_2d(:,2) = p3_2d(:,2) + v2(:,i).*v2nb(:,i);
end

% calculate the fitting circle
% due to the special construction of the 2d system this boils down to solving
% q1 = [0,0], q2 = [a,0], q3 = [b,c] (points on 2d circle)
% crossing perpendicular bisectors, s and t running indices:
% solve [a/2,s] = [b/2 + c*t, c/2 - b*t]
% solution t = (a-b)/(2*c)

a = l1;b = p3_2d(:,1);c = p3_2d(:,2);
t = 0.5*(a-b)./c;
scale1 = b/2 + c.*t;scale2 = c/2 - b.*t;

% centers
center = zeros(n,3);
for i=1:3,
    center(:,i) = p1(:,i) + scale1.*v1n(:,i) + scale2.*v2nb(:,i);
end

% radii
rad = sqrt((center(:,1)-p1(:,1)).^2+(center(:,2)-p1(:,2)).^2+(center(:,3)-p1(:,3)).^2);

2Â¥2013-05-02 09:22:48
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

zhhhero

Í­³æ (³õÈëÎÄ̳)

¶ÔÁË£¬ÎÒÊÇÓÐ10×é¿Õ¼äµãÈýÎ¬×ø±ê£¬ÏÖÔÚÏëÄâºÏ¿Õ¼äÔ²¡£
ѧµ½ÀÏ£¬»îµ½ÀÏ
3Â¥2013-05-02 09:58:24
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

dbb627

ÈÙÓþ°æÖ÷ (ÖøÃûдÊÖ)

¡¾´ð°¸¡¿Ó¦Öú»ØÌû

¡ï
¸Ðл²ÎÓ룬ӦÖúÖ¸Êý +1
xiegangmai: ½ð±Ò+1, лл²ÎÓ룡 2013-05-02 23:10:45
¿Õ¼äÔ²µÄµã±ØÈ»¹²Ã棬½«¿Õ¼ä×ø±êתµ½Æ½Ãæ×ø±êÏ£¬ÄâºÏºóÔÙת»ØÈ¥¡£
The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
4Â¥2013-05-02 10:23:35
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] 08¹¤¿Æ 320×Ü·Ö Çóµ÷¼Á +8 À滨çóÍí·ç 2026-03-17 8/400 2026-03-22 14:30 by ÐÒÔ˵Ľ´½´
[¿¼ÑÐ] Ò»Ö¾Ô¸±±¾©»¯¹¤´óѧ070300 ѧ˶336Çóµ÷¼Á +5 vvÃÔ 2026-03-21 8/400 2026-03-22 14:20 by ColorlessPI
[¿¼ÑÐ] Ò»Ö¾Ô¸¶«»ª´óѧ»¯Ñ§070300£¬Çóµ÷¼Á +5 2117205181 2026-03-21 6/300 2026-03-22 14:18 by ColorlessPI
[¿¼ÑÐ] ¿¼Ñе÷¼Á +4 À´ºÃÔËÀ´À´À´ 2026-03-21 4/200 2026-03-22 12:15 by ÐÇ¿ÕÐÇÔÂ
[¿¼ÑÐ] 354Çóµ÷¼Á +7 Tyoumou 2026-03-18 10/500 2026-03-22 11:11 by ÈËÀ´Ê¢
[¿¼ÑÐ] 085600²ÄÁÏÓ뻯¹¤306 +4 z1z2z3879 2026-03-21 4/200 2026-03-21 23:44 by ms629
[¿¼ÑÐ] Ò»Ö¾Ô¸Î÷°²½»Í¨´óѧ²ÄÁϹ¤³Ìרҵ 282·ÖÇóµ÷¼Á +10 ·ãÇÅZL 2026-03-18 12/600 2026-03-21 22:02 by peike
[¿¼ÑÐ] 333Çóµ÷¼Á +5 87639 2026-03-21 7/350 2026-03-21 19:31 by ColorlessPI
[¿¼ÑÐ] 336Çóµ÷¼Á +5 rmc8866 2026-03-21 5/250 2026-03-21 17:24 by ѧԱ8dgXkO
[¿¼ÑÐ] 265Çóµ÷¼Á +3 Jack?k?y 2026-03-17 3/150 2026-03-21 03:17 by JourneyLucky
[¿¼ÑÐ] »ª¶«Ê¦·¶´óѧ-071000ÉúÎïѧ-293·Ö-Çóµ÷¼Á +3 Ñо¿ÉúºÎÑþÃ÷ 2026-03-18 3/150 2026-03-21 01:30 by JourneyLucky
[¿¼ÑÐ] 324·Ö 085600²ÄÁÏ»¯¹¤Çóµ÷¼Á +4 llllkkkhh 2026-03-18 4/200 2026-03-21 01:24 by JourneyLucky
[¿¼ÑÐ] 296Çóµ÷¼Á +6 www_q 2026-03-18 10/500 2026-03-20 23:56 by JourneyLucky
[¿¼ÑÐ] Ò»Ö¾Ô¸Î÷°²½»Í¨´óѧ ѧ˶ 354Çóµ÷¼Á211»òÕß˫һÁ÷ +3 ÎÒÏëÒª¶ÁÑо¿Éú 2026-03-20 3/150 2026-03-20 20:13 by JourneyLucky
[¿¼ÑÐ] 353Çóµ÷¼Á +3 À­¹³²»Ðí±ä 2026-03-20 3/150 2026-03-20 19:56 by JourneyLucky
[¿¼ÑÐ] ¹¤¿Æ²ÄÁÏ085601 279Çóµ÷¼Á +7 À§ÓÚÐdz¿ 2026-03-17 9/450 2026-03-20 17:38 by ÎÞи¿É»÷111
[¿¼ÑÐ] 312Çóµ÷¼Á +8 İå·Ï£ 2026-03-16 9/450 2026-03-18 12:39 by Linda Hu
[¿¼ÑÐ] 334Çóµ÷¼Á +3 Ö¾´æ¸ßÔ¶ÒâÔÚ»úÐ 2026-03-16 3/150 2026-03-18 08:34 by lm4875102
[¿¼ÑÐ] 308Çóµ÷¼Á +4 ÊÇLupa°¡ 2026-03-16 4/200 2026-03-17 17:12 by ruiyingmiao
[¿¼ÑÐ] 0856Çóµ÷¼Á +3 ÁõÃÎ΢ 2026-03-15 3/150 2026-03-16 10:00 by houyaoxu
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û