How can I place spheres along a circle/ring ?
2 views (last 30 days)
Show older comments
Shankar Lingesh Dhanuskodi
on 11 Jun 2018
Commented: Anton Semechko
on 20 Jun 2018
Hi everyone! I am working on a project where I have a sphere.Now I want to replicate the sphere and place them in a circular manner(3D plot).I would be glad, If someone could help me with this!
Eg: Imagine showing the position of the earth in its orbit(Circular orbit in this case) every month of the year. Now I imagine, we would have 12 spheres in a orbit.
3 Comments
Aquatris
on 11 Jun 2018
@Guillaume, cause those are not my answers and in my opinion, it would be unethical to copy paste others work. That is why I just referenced them as a comment.
Accepted Answer
Anton Semechko
on 11 Jun 2018
% Unit sphere
TR=IcosahedronMesh;
TR=SubdivideSphericalMesh(TR,5);
[Tri,X]=GetMeshData(TR);
% Reference meridian
t=linspace(0,pi,5E2)';
M=zeros(numel(t),3);
M(:,2)=sin(t);
M(:,3)=cos(t);
% Circular orbit
t=linspace(0,2*pi,1E3+1)';
R=10; % radius of the orbit
O=R*[cos(t) sin(t)];
% 12 equaly spaced points along the orbit
t_o=linspace(0,2*pi,13)'; t_o(end)=[];
C=R*[cos(t_o) sin(t_o)];
C(:,3)=0;
% Visualize orbit
figure('color','w')
axis equal off
hold on
plot(O(:,1),O(:,2),'--b','LineWidth',2)
view([20 20])
% Visualize sphere at 12 equally-spaced positions along the orbit
for i=1:size(C,1)
% Rotation around z-axis
c=cos(t_o(i));
s=sin(t_o(i));
R=[c -s 0;s c 0;0 0 1];
% Rotate and translate mesh
Xi=bsxfun(@plus,(R*X')',C(i,:));
h=trimesh(triangulation(Tri,Xi));
set(h,'EdgeColor','none','FaceColor',0.75*[1 1 1],'FaceAlpha',0.9);
% Rotate and translate reference meridian
Mi=bsxfun(@plus,(R*M')',C(i,:));
plot3(Mi(:,1),Mi(:,2),Mi(:,3),'-k','LineWidth',2)
end
zoom(2)
7 Comments
Guillaume
on 18 Jun 2018
The code under
% Rotate and translate mesh
draws the spheres. The code under
% Rotate and translate reference meridian
plots the black line. You must have suppressed the wrong section.
As for the properties of the sphere they're all defined by
set(h,'EdgeColor','none','FaceColor',0.75*[1 1 1],'FaceAlpha',0.9);
Change the FaceColor to black if you want black:
set(h,'EdgeColor','none','FaceColor', 'k');
Anton Semechko
on 20 Jun 2018
@ Guillaume, all functions used in this demo can be found on FEX as part of 'Suite of functions to perform uniform sampling of a sphere'
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!