ROTATE Function
Returns a rotated and/or transposed copy of the input array.
Usage
result = ROTATE(array, direction)
Input Parameters
array—The 1D, 2D, or 3D array to be rotated.
directionAn integer that specifies the type of rotation to be performed, as shown in Table 15-2: Direction Values.
 
Direction Values
Direction
Transpose
Rotation Clockwise
0
No
None
1
No
90°
2
No
180°
3
No
270°
4
Yes
None
5
Yes
90°
6
Yes
180°
7
Yes
270°
The input parameter direction is taken modulo 8, so a rotation of –1 is the same as 7, 9 is the same as 1, and so forth.
Returned Value
result—A copy of array that has been rotated and/or transposed by 90-degree increments.
Keywords
None.
Discussion
The ROTATE function supports multi-layer band interleaved images. When the input array is three-dimensional, it is automatically treated as an array of images, array(m, n, p), where p is the number of m by n images. Each image is then operated on separately and an array of the result images is returned.
The resulting array is of the same data type as the input array. The dimensions of the result are the same as those of array if direction is equal to 0 or 2; the dimensions are switched if direction is 1 or 3.
 
note
To rotate by amounts other than multiples of 90 degrees, use the functions ROT and ROT_INT. However, ROTATE is more efficient than either of those functions.
Example 1
ROTATE may be used to reverse the order of elements in vectors. For example, to reverse the order of elements in the vector in variable X:
x = [0, 1, 2, 3]
x1 = ROTATE(x, 2)
PM, x, x1
; PV-WAVE prints:
;  0       1       2       3
;  3       2       1       0
Results in:
ROTATE(X,2) = [3,2,1,0]
Example 2
This example uses ROTATE to rotate an image by 90 degrees counterclockwise and displays the image both before and after the rotation. The results are shown in Figure 15-4: Original Image and Rotations.
; Open the file containing the image.
OPENR, unit, !Data_dir + 'x2y2.dat', /Get_Lun
; Create array to hold image, read image, and free the LUN.
img = BYTARR(320, 256)
READU, unit, img
FREE_LUN, unit
; Create a window.
WINDOW, 0, Xsize=640, Ysize=640
; Display the image, before, and after rotations.
TV, img, 0, 321
TV, ROTATE(img, 1), 321, 257
TV, ROTATE(img, 2), 0, 0
TV, ROTATE(img, 3), 321, 0
 
Figure 15-4: Original Image and Rotations
See Also