rotate the sphere around the circle of the torus

2 visualizzazioni (ultimi 30 giorni)
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);

Risposte (2)

Atsushi Ueno
Atsushi Ueno il 1 Giu 2020
"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

KSSV
KSSV il 1 Giu 2020
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 Commento
Adam Danz
Adam Danz il 11 Giu 2020
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.

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by