Effacer les filtres
Effacer les filtres

How to pick well known points on a sphere ?

7 vues (au cours des 30 derniers jours)
jiji hr
jiji hr le 20 Juin 2016
Commenté : jiji hr le 21 Juin 2016
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.

Réponse acceptée

Roger Stafford
Roger Stafford le 20 Juin 2016
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 commentaire
jiji hr
jiji hr le 21 Juin 2016
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

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by