how do i rotate a sphere

40 views (last 30 days)
Alex
Alex on 5 Apr 2019
Edited: Amal George M on 9 Apr 2019
How do i make the sphere move around the z axis and up down the z axis with the following incomplete code?
Do not change both at the same time.
syms u v
r = input('r=')
n = input('n=')
for i = 1:n
t(i) =
x = r*cos(u)*sin(v);
y = r*sin(u)*sin(v);
z = r*cos(v);
s=fsurf(x,y,z);
drawnow

Answers (1)

Amal George M
Amal George M on 9 Apr 2019
Edited: Amal George M on 9 Apr 2019
This can be done using 'fanimator'. The sample code animates translation along z axis.
syms u v t
r=0.9; % fixed radius
x = r*cos(u)*sin(v);
y = r*sin(u)*sin(v);
z = r*cos(v);
f=figure;
ax=axes;
axis equal;
view(3); %3D view
ax.XLim=[-1 1];
ax.YLim=[-1 1];
ax.ZLim=[-1 10];
ax.Box='on'; % border
hold on
f = fanimator(@fsurf,x,y,z+t,'AnimationRange',[0 9]);
hold off
playAnimation

Community Treasure Hunt

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

Start Hunting!