How can I place spheres along a circle/ring ?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Aquatris
2018-6-11
@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.
采纳的回答
Anton Semechko
2018-6-11
% 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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189170/image.jpeg)
7 个评论
Guillaume
2018-6-18
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
2018-6-20
@ 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'
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!