matlab中如何實現三維圖像以指定角度旋轉,坐標軸不變?
題主所說的在保持坐標軸不變的情況下,對圖像進行特定角度的旋轉,其實就是將圖像按照某一固定軸旋轉一定角度。MATLAB中可以通過rotate函數實現(區別於view和rotate3d,它們只改便3D圖形的視角,並不旋轉圖像本身)。
首先,看一下如何對旋轉軸進行刻畫,一般有兩種方式:- 以[]表示的向量作為旋轉軸,即笛卡爾形式(Cartesian candidates),示意圖如下
- 以[]表示的球坐標(spherical candidates)為的旋轉軸,其中為旋轉軸在平面投影與正半軸的夾角,為旋轉軸與平面所成夾角,示意圖如下
rotate(h,direction,alpha,origin)
h is the graphics object.
direction is a two- or three-element vector that describes the axis of rotation.positive alpha is defined as the righthand-rule angle about the direction vector as it extends from the origin of rotation.origin is a three-element vector which describes the origin of the axis of rotation.
- h為待旋轉的圖像對象
- direction為以笛卡爾或球坐標表示的旋轉軸,對應為3維和2維向量
- alpha 為旋轉角度
- origin 表示旋轉軸的起始點
figure
sp11=subplot(2,2,1);
h11=surf(sp11,peaks(35));
title("No Rotation")
sp12=subplot(2,2,2);
h12=surf(sp12,peaks(35));
title("Rotation Around [1 1 1]-Axis")
zdir=[1 1 1];
rotate(h12,zdir,30)
sp21=subplot(2,2,3);
h21=surf(sp21,peaks(35));
title("Rotation Around [1 1 1]-Axis")
zdir=[45 45];
rotate(h21,zdir,30)
sp22=subplot(2,2,4);
h22=surf(sp22,peaks(35));
title("Rotation Around Z-Axis")
zdir=[0 90];
rotate(h22,zdir,90)
效果圖如下:
- 以上內容主要參考MATLAB強大的幫助文檔,部分截圖也出自源文檔。
- 作為一個學術界的搬運工,希望能幫到題主~
rotate Rotate objects about specified origin and direction.
rotate(H,[THETA PHI],ALPHA) rotates the objects with handles H through angle ALPHA about an axis described by the 2-element direction vector [THETA PHI] (spherical coordinates). All the angles are in degrees. The handles in H must be children of the same axes.THETA is the angle in the xy plane counterclockwise from the positive x axis. PHI is the elevation of the direction vector from the xy plane (see also SPH2CART). Positive ALPHA is defined as the righthand-rule angle about the direction vector as it extends from the origin.rotate(H,[X Y Z],ALPHA) rotates the objects about the direction vector [X Y Z] (Cartesian coordinates). The direction vector is the vector from the center of the plot box to (X,Y,Z).rotate(...,ORIGIN) uses the point ORIGIN = [x0,y0,z0] as the center of rotation instead of the center of the plot box.
如果想要對複雜曲面(包含數據較多)旋轉或者做其他放射變換的話請用hgtransform(變換矩陣可以用makehgtform構建)這樣的好處(在比較新的版本)是只需要向GPU傳遞一個4x4的變換矩陣由GPU對圖像重新渲染,而rotate的處理方式是提取數據並對數據計算(在內存中用CPU計算)之後重新交由GPU渲染,當被旋轉對象數據量較大時性能顯然不如前者,這一點尤其能在連續變換的動畫中體現出來
推薦閱讀:
※Matlab中disp、fprintf和sprintf有什麼區別?
※怎麼鍛煉 MATLAB 編程能力?
※matlab有什麼不能做的事情?
※Lingo和Matlab在解決最優化問題的時候的優缺點?
※matlab畫圖,明明標記了11個點的坐標,最後畫出來的圖卻只有10個點,坐標沒有重疊。這是為什麼?