%% Apply Rotation and Translation to Surface Plot
% Apply rotation and translation to the surface plot of a torus.
% A torus can be defined parametrically by
% \begin{array}{l}
% x\left(\theta \;,\varphi \;\right)=\left(R+a\;\cos \;\theta \right)\;\cos \;\varphi \\
% y\left(\theta \;,\varphi \;\right)=\left(R+a\;\cos \;\theta \right)\;\sin \;\varphi \\
% z\left(\theta \;,\varphi \;\right)=a\;\sin \;\varphi
% \end{array}
% where
% \theta \; is the polar angle and \varphi \; is the azimuthal angle
% a is the radius of the tube
% R is the distance from the center of the tube to the center of the torus
% Define the values for a and R as 1 and 5, respectively. Plot the torus using fsurf.

syms theta phi
a = 1;
R = 4;
x = (R + a*cos(theta))*cos(phi);
y = (R + a*cos(theta))*sin(phi);
z = a*sin(theta);
fsurf(x,y,z,[0 2*pi 0 2*pi])
hold on

% Apply rotation to the torus around the x-axis. Define the rotation matrix. Rotate the torus by 90 degrees or \pi/2 radians.

alpha = pi/2;
Rx = [1 0 0;
      0 cos(alpha) -sin(alpha);
      0 sin(alpha) cos(alpha)];
r = [x; y; z];
r_90 = Rx*r;

% Shift the center of the torus by 5 along the x-axis. Add a second plot of the rotated and translated torus to the existing graph.

fsurf(r_90(1)+5,r_90(2),r_90(3))
axis([-5 10 -5 10 -5 5])
hold off

%
% Copyright 2019 The MathWorks, Inc.