clc;
clear;
[X,Y,Z] = peaks;
%
subplot(1,2,1)
surf(X,Y,Z);
title("原始");
%
subplot(1,2,2)
h=surf(X,Y,Z);
rotate(h,[1,0,0],90,[0,0,0]);
title("官方函数,绕X轴,逆时针旋转90°");
%matlab绘图运用右手坐标系。
%在右手坐标系中,旋转角的正方向为逆时针方向。
clc;
clear;
[X,Y,Z] = peaks;
%
subplot(1,2,1)
surf(X,Y,Z);
title("原始");
%
subplot(1,2,2)
h=surf(X,Y,Z);
direction=[1,1,0];
origin=[0,0,0];
rotate(h,direction,90,origin);
title("官方函数,绕direction归一化后得到的点P[0.7071,0.7071,0]与origin共同确定的旋转轴旋转,逆时针旋转90°");
%[1]注意,这条旋转轴不再是某条坐标轴了。
%[2]踩坑提示,千万不要认为[1,1,0],90是指先绕x轴旋转90°再绕y轴旋转90°,可能被官方文档一处例子误导。
%[3]向量归一化指[向量中的每个元素]依次除以该[向量的模],使该向量成为单位向量,单位向量是指模等于1的向量,方向任意,有无数个。
%[4]单位向量=原向量(:)/norm(原向量);
%[5]rotate源码第44行计算点P也就是u。
%[6]官方函数无法原文档编辑,可以复制一份到自建.m文件即可编辑。
clc;
clear;
[X,Y,Z] = peaks;
%
subplot(2,3,1)
surf(X,Y,Z);
title("原始");
%
subplot(2,3,4)
h1=surf(X,Y,Z);
rotate(h1,[1,0,0],60,[0,0,0]);
title("官方函数,绕X轴旋转,逆时针旋转60°");
%
subplot(2,3,5)
h2=surf(X,Y,Z);
rotate(h2,[1,0,0],60,[0,0,0]);
rotate(h2,[0,1,0],60,[0,0,0]);
title("官方函数,先绕X轴旋转,再绕Y轴旋转,逆时针旋转60°");
%
subplot(2,3,6)
h3=surf(X,Y,Z);
rotate(h3,[1,0,0],60,[0,0,0]);
rotate(h3,[0,1,0],30,[0,0,0]);
rotate(h3,[0,0,1],45,[0,0,0]);
title("官方函数,先绕X轴旋转60°,再绕Y轴旋转30°,最后绕Z轴旋转45°");