%% Rotate Surface
% This example shows how to rotate a surface about the _y_-axis.
%% Create Surface and Transform
% Parent the surface to the transform object.

% Copyright 2015 The MathWorks, Inc.

t = hgtransform;
surf(peaks(40),'Parent',t)
view(-20,30)
axis manual
%% Create Transform 
% Set a _y_-axis rotation matrix to rotate the surface by -15 degrees.
ry_angle = -15*pi/180; 
Ry = makehgtform('yrotate',ry_angle);
t.Matrix = Ry;

%%
% The surface rotated -15 degrees about the _y_-axis that passes through 
% the origin. 

%% Translate the Surface and Rotate
% Now rotate the surface about the _y_-axis that passes
% through the point x = 20.
%
% Create two translation matrices, one to translate the surface -20 units
% in x and another to translate 20 units back. Concatenate the two
% translation matrices with the rotation matrix in the correct order and
% set the transform.
Tx1 = makehgtform('translate',[-20 0 0]);
Tx2 = makehgtform('translate',[20 0 0]);
t.Matrix = Tx2*Ry*Tx1;