How to pick points on a sphere I have already obtained by the minimum bounding sphere ?
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I want to pick a randomly distributed uniform set of points on a sphere that I have already obtained using the minimum bounding sphere methode on a 3D object minimum bounding sphere .
What i did is like that: In the function VisualizeBoundSphere.m I introduced this code source :
TH = 2*pi*rand(1,100);
  PH = asin(-1+2*rand(1,100));
  [Abssice,Ordonne,Onsoub] = sph2cart(TH,PH,R);
  H(6)= plot3(Abssice,Ordonne,Onsoub,'.','markersize',1);
to understand more the parametre i put the content of the function here :
            function H=VisualizeBoundSphere(X,R,C)
              % Visualize a point cloud (or a triangular surface mesh) and its bounding
              % sphere.
              %
              %   - X     : M-by-3 list of point coordinates or a triangular surface mesh
              %             specified as a TriRep object.
              %   - R     : radius of the sphere.
              %   - C     : 1-by-3 vector specifying the centroid of the sphere.
              %   - H     : 1-by-6 vector containing handles for the following objects: 
              %               H(1)    : handle of the point cloud/mesh 
              %               H(2)    : handle for the sphere
              %               H(3:5)  : handles for the great circles 
              %               H(6)    : handle for the light used to illuminate the scene 
              %
              % AUTHOR: Anton Semechko (a.semechko@gmail.com)
              % DATE: Dec.2014
              %
              if nargin<2 || isempty(R) || isempty(C)
                  [R,C]=ExactMinBoundSphere3D(X);
              end
              % Generate a spherical mesh
              tr=SubdivideSphericalMesh(IcosahedronMesh,4);
              tr=TriRep(tr.Triangulation,bsxfun(@plus,R*tr.X,C));
              % Construct great circles 
              t=linspace(0,2*pi,1E3);
              x=R*cos(t);
              y=R*sin(t);
              [GC1,GC2,GC3]=deal(zeros(1E3,3));
              GC1(:,1)=x; GC1(:,2)=y; % xy-plane
              GC2(:,1)=y; GC2(:,3)=x; % zx-plane
              GC3(:,2)=x; GC3(:,3)=y; % yz-plane
              GC1=bsxfun(@plus,GC1,C);
              GC2=bsxfun(@plus,GC2,C);
              GC3=bsxfun(@plus,GC3,C);
              % Visualize the point cloud/mesh
              H=zeros(1,7);
              figure('color','w')
              if strcmpi(class(X),'TriRep')
                  H(1)=trimesh(X);
                  set(H(1),'EdgeColor','none','FaceColor','g')
              else
                  H(1)=plot3(X(:,1),X(:,2),X(:,3),'.k','MarkerSize',20);
              end
              axis equal off
              hold on
              % Visualize the sphere and the great circles
              TH = 2*pi*rand(1,100);
              PH = asin(-1+2*rand(1,100));
              [Abssice,Ordonne,Onsoub] = sph2cart(TH,PH,R);
              H(2)=trimesh(tr);
              set(H(2),'EdgeColor','none','FaceColor','r','FaceAlpha',0.5)
              H(3)=plot3(GC1(:,1),GC1(:,2),GC1(:,3),'-k','LineWidth',2);
              H(4)=plot3(GC2(:,1),GC2(:,2),GC2(:,3),'-k','LineWidth',2);
              H(5)=plot3(GC3(:,1),GC3(:,2),GC3(:,3),'-k','LineWidth',2);
              H(6)= plot3(Abssice,Ordonne,Onsoub,'.','markersize',1); 
              axis tight vis3d
              % Add some lighting and we are done
              H(7)=light;
              lighting phong
That gives me this result but it is not picked on the surface of the sphere.

0 comentarios
Respuestas (1)
  TED MOSBY
 el 13 de Ag. de 2025
        Hi,
The problem may be arising due to sph2cart returning coordinates for a sphere centered at the origin. Your bounding sphere has center C, so you need to translate the points by C after converting from spherical coordinates. Otherwise, the points will sit on a radius-R sphere around [0,0,0], not around your red sphere. (Also, sph2cart takes (azimuth, elevation, r), where elevation is measured from the x–y plane.) 
n = 1000;                           % random surface points
dirs = randn(n,3);                  % random directions
dirs = dirs ./ vecnorm(dirs,2,2);   % unit vectors
P = C + R*dirs;                     % translate to center C and scale to radius R
H(6) = plot3(P(:,1),P(:,2),P(:,3),'.','MarkerSize',6);
% ... rest of your lighting/axis code ...
Hope it helps!
0 comentarios
Ver también
Categorías
				Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

