필터 지우기
필터 지우기

How to pick well known points on a sphere ?

조회 수: 7 (최근 30일)
jiji hr
jiji hr 2016년 6월 20일
댓글: jiji hr 2016년 6월 21일
Hello, Here I am again, I implemented this code acording to an algorithm presented in this article so normally it is like this :
function [ x,y,z ] = RegularPlacement( R,N )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
Ncpt = 0;
a = 4*pi*R*R/N ;
d = sqrt(a);
Mv = round(pi/d);
dv = pi/Mv;
dphi = a/dv;
for m = 0 : Mv-1
v = pi*(m+0.5)/Mv;
Mphi = round(2*pi*sin(v)/dphi);
for n = 0 : Mphi-1
phi = 2*pi*n/Mphi;
i = n+1;
x(i) = R*sin(v)*cos(phi);
y(i) = R*sin(v)*sin(phi);
z(i) = R*cos(v);
Ncpt = Ncpt +1;
end
end
end
So I get 3 arrays, and my objectif is to pick those points on a sphere.
I am sorry I m not used with matlab and I really found a difficulties to understand how should it works. waht I tried is like this :
[ x,y,z ] = RegularPlacement( 1,300 )
m = [x;y;z]
m = bsxfun(@rdivide,m,sqrt(sum(m.^2,1)));
plot3(m(1,:),m(2,:),m(3,:),'.');
axis equal;
But it doen't give me what I am seeking about.

채택된 답변

Roger Stafford
Roger Stafford 2016년 6월 20일
The problem is with the line “i = n+1” in your function. It is located inside the inner loop whose index is n. This means that it repeats the values of i for each trip through the outer loop, and all you get are about 31 values, since most of values have been overwritten.
Instead of that line you should put i = 0 before you enter either loop. Then inside you should have i = i+1. That way you will get all the values of x, y, and z that are generated in the two loops.
  댓글 수: 1
jiji hr
jiji hr 2016년 6월 21일
Thanks for help, it is working. But now I have an other problem, I have this results from the code source abouve :
and in the other side I have the results from the minimum bounding sphere function with outputs are the center and tha radius of the sphere:
When I was trying to understand the code source, I encountred this ligne :
tr=TriRep(tr.Triangulation,bsxfun(@plus,R*tr.X,C));
I can say that it means that we put objects inside the sphere and we are normalize them so that they fit the sphere and mathematically I can say it is to change the coordinates of verteice of the object like that:
x1 = R*x+C
y1 = R*y+C
z1 = R*z+C.
So the objects here ara already normalized. So my 2 questions are : first : is this analysis I gave is correct or not, according to the line of source code ? Second : I want to merge the 2 figure in such way I get the points picked on the surface of the minimum bounding sphere, theorically we have to fit centers maybe but I don't know what are the functions I have to use in matlab and how to do it? I tried to do this but it gave me a horrible results :
x=bsxfun(@plus,x,C(1));
y=bsxfun(@plus,y,C(2));
z=bsxfun(@plus,z,C(3));
.....
H=zeros(1,5);
hold on
H(4) = plot3(m(1,:),m(2,:),m(3,:),'.');
axis equal

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by