필터 지우기
필터 지우기

Draw the sphere to find the radius of the sphere

조회 수: 1 (최근 30일)
Sterne_17
Sterne_17 2023년 2월 3일
댓글: DGM 2023년 2월 4일
I want to fit a 3D sphere, and my goal is to find the radius of the sphere. Knowing the coordinates of some points on the sphere (x,y,z,), which function should I use to quickly draw a sphere and know its radius?

채택된 답변

John D'Errico
John D'Errico 2023년 2월 3일
Estimation of the sphere parameters is not too difficult. First, since you have shown no data, I'll make some up.
XYZ = randn(50,3); XYZ = XYZ./sqrt(sum(XYZ.^2,2));
XYZ = 2.5*XYZ + [1 3 5] + randn(size(XYZ))/20;
plot3(XYZ(:,1),XYZ(:,2),XYZ(:,3),'o')
axis equal
grid on
box on
xlabel 'X'
ylabel 'Y'
zlabel 'Z'
The result should be a sphere of radius 2.5, centered at the point [1 3 5].
You can use the tool I attached called spherefit.
[C,R] = spherefit(XYZ)
C = 1×3
0.9925 3.0094 5.0107
R = 2.5086
As you can see, the code recovered the original parameters well enough. Now, to plot the sphere...
fimplicit3(@(x,y,z) (x - C(1)).^2 + (y - C(2)).^2 + (z - C(3)).^2 - R.^2)
hold on
plot3(XYZ(:,1),XYZ(:,2),XYZ(:,3),'ro')
axis equal
grid on
box on
xlabel 'X'
ylabel 'Y'
zlabel 'Z'
hold off
I could have built a surface directly, perhaps using meshgrid. But fimplicit3 is just too easy.
  댓글 수: 3
John D'Errico
John D'Errico 2023년 2월 4일
That is a completely different question, significantly different from what you asked and I answered. You will first need to use image processing tools, identifying the pixels on that perimeter. But then you still cannot easily convert a picture of the outline of a sphere into a sphere, since the picture lacks depth information. Anyway, I don't do image processing.
Sterne_17
Sterne_17 2023년 2월 4일
편집: Sterne_17 2023년 2월 4일
I already know the coordinates (x,y,z) of several scatter points on the sphere in space, and I think I just need to bring their coordinates into the code you showed. I was wondering how to bring in the coordinates of these points? @John D'Errico
XYZ = randn(50,3); XYZ = XYZ./sqrt(sum(XYZ.^2,2));
XYZ = 2.5*XYZ + [1 3 5] + randn(size(XYZ))/20;
plot3(XYZ(:,1),XYZ(:,2),XYZ(:,3),'o')
axis equal
grid on
box on
xlabel 'X'
ylabel 'Y'
zlabel 'Z'

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by