MATLAB: How to use the view transform matrix to map 3-D plots to 2-D

MATLAB

t=0:pi/50:10*pi;
x=sin(t);
y=cos(t);
In=[x',y',t',ones(501,1)]';
plot3(x,y,t);
T1=view;
figure;
Out1=T1*In;
plot(Out1(1,:),Out1(2,:));

Best Answer

When MATLAB applies a view transform it does it to a space that is normalized. Rotation must happen in this space, otherwise scaling effects will corrupt the plot.
Take the above example and modify it to read:
t=0:pi/50:10*pi;
x=sin(t);
y=cos(t);
In=[x',y',t',ones(501,1)]';
plot3(x,y,t);
T1=view;
norm = eye(4);
norm(1,1) = 1/diff(get(gca,'xlim'));
norm(2,2) = 1/diff(get(gca,'ylim'));
norm(3,3) = 1/diff(get(gca,'zlim'));
figure;
Out1=T1*norm*In;
plot(Out1(1,:),Out1(2,:));
Note: All that was added was the multiplication by the norm matrix which normalizes the data.