rotate the sphere around the circle of the torus
2 次查看(过去 30 天)
显示 更早的评论
Please help us solve the problem. You must rotate the sphere around the circle of the torus
%Строим тор
R=20;
r=5;
[a, b] = meshgrid(0:20/180*pi:2*pi);
X=((R-r)+r*cos(a)).*cos(b);
Y=((R-r)+r*cos(a)).*sin(b);
Z=r.*sin(a);
hsurf = surf(X,Y,Z,'FaceColor','interp','FaceAlpha',0.2,'EdgeAlpha',0.3);
axis equal; hold on
%Создаем шарик 1
hold on
[x,y,z]=sphere;
x1=x-15;
z1=z;
y1=y;
l1=surf(x1,y1,z1);
0 个评论
回答(2 个)
Atsushi Ueno
2020-6-1
"rotate the sphere around the circle of the torus" means like this?
%Строим тор
R=20;
r=5;
[a, b] = meshgrid(0:20/180*pi:2*pi);
X=((R-r)+r*cos(a)).*cos(b);
Y=((R-r)+r*cos(a)).*sin(b);
Z=r.*sin(a);
hsurf = surf(X,Y,Z,'FaceColor','interp','FaceAlpha',0.2,'EdgeAlpha',0.3);
axis equal; hold on
%Создаем шарик 1
hold on
[x,y,z]=sphere;
for th1 = 0:45/180*pi:2*pi
for th2 = 0:45/180*pi:2*pi
x1=x + ((R-r) + r * cos(th1)) * cos(th2);
y1=y + ((R-r) + r * cos(th1)) * sin(th2);
z1=z + r * sin(th1);
l1=surf(x1,y1,z1);
end
end
0 个评论
KSSV
2020-6-1
R=20;
r=5;
[a, b] = meshgrid(0:20/180*pi:2*pi);
X=((R-r)+r*cos(a)).*cos(b);
Y=((R-r)+r*cos(a)).*sin(b);
Z=r.*sin(a);
hsurf = surf(X,Y,Z,'FaceColor','interp','FaceAlpha',0.2,'EdgeAlpha',0.3);
axis equal; hold on
%??????? ????? 1
hold on
[x,y,z]=sphere;
x1=x;
z1=z;
y1=y;
l1=surf(x1,y1,z1);
%% Animation
th = linspace(0,2*pi);
xc = R*cos(th) ;
yc = R*sin(th) ;
% Draw sphere around torus
for i = 1:100
figure(1)
hold on
surf(X,Y,Z,'FaceColor','interp','FaceAlpha',0.2,'EdgeAlpha',0.3);
surf(x1+xc(i),y1+yc(i),z1)
hold off
end
1 个评论
Adam Danz
2020-6-11
Faster & more efficient,
% Draw sphere around torus
hold on
for i = 1:100
surf(x1+xc(i),y1+yc(i),z1)
drawnow
end
otherwise you're redrawing the torus over and over again. Calling figure() repetitively also slows things down.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!