How can I place spheres along a circle/ring ?

조회 수: 4 (최근 30일)
Shankar Lingesh Dhanuskodi
Shankar Lingesh Dhanuskodi 2018년 6월 11일
댓글: Anton Semechko 2018년 6월 20일
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
Guillaume
Guillaume 2018년 6월 11일
@Aquatris, why don't you write that as an answer rather than a comment?
Aquatris
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
Anton Semechko 2018년 6월 11일
See example below. All relevant functions used to generate this example can be found here .
% 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
Guillaume
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
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 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