Fit a circle to 3d dots
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi, I have dots spread like a tube in a 3d space. I want to fit a circle to this data (the data is attached). The plane that the circle should be in is:
S1=[-15.8,8.6,1.3];
S2=[-10.5,10.3,-3.3];
S3=[-15.2,8.9,1.6];
normal = cross(S1-S2, S1-S3);
A = normal(1); B = normal(2); C = normal(3);
D = dot(normal,S1);
This is what I was trying to do:
plot3(n1,n2,n3,'*') %The dots
hold on
a2=[mean(n1),mean(n2),mean(n3)]; %Center of the dots
plot3(a2(1),a2(2),a2(3),'*','color','g')
a3=dist(a2,[n1;n2;n3]); %calculate the radius
t = linspace(0,2*pi,40);
x=(mean(a3).*sin(t)+mean(n1));
y=(mean(a3).*cos(t)+mean(n2));
z = (A * x + B * y - D)/(-C);
plot3(x,y,z,'*','color','r')
But I can't set the circle right in place (it is grater than what it should be). could you help?
채택된 답변
Mischa Kim
2014년 1월 31일
There is probably something not working with the way you rotate the circle back into the plane. This works:
S1=[-15.8,8.6,1.3];
S2=[-10.5,10.3,-3.3];
S3=[-15.2,8.9,1.6];
normal = cross(S1-S2, S1-S3); % compute reference frame axes
nz = normal'/norm(normal);
normal2 = cross(nz, [0; 1; 0]);
nx = normal2/norm(normal2);
ny = cross(nz, nx)/norm(cross(nz, nx)); % end compute reference frame axes
R = [nx ny nz]; % compute rotation matrix
plot3(n1,n2,n3,'*') %The dots
hold on; grid; box;
a2=[mean(n1),mean(n2),mean(n3)]; %Center of the dots
plot3(a2(1),a2(2),a2(3),'*','color','g')
a3=dist(a2,[n1;n2;n3]); %calculate the radius
t = linspace(0,2*pi,40);
x0=(mean(a3).*sin(t)); % get circle coordinates in x-y plane...
y0=(mean(a3).*cos(t));
z0 = zeros(1,length(x0));
xyz = bsxfun(@plus, R*[x0; y0; z0], a2'); % rotate circle plane and adjust center
plot3(xyz(1,:),xyz(2,:),xyz(3,:),'-','color','r')
댓글 수: 0
추가 답변 (1개)
Iain
2014년 1월 31일
Without looking at the data, it looks like the size of your circle would be larger than it should be because of the spots being off the plane where your circle exists.
Either you should reform your formula to fit the best circle in 3D space (that should be a page or two of working out the formulae), or, you should calculate the closest point on your plane to each point, and then use those points to fit your circle.
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!