Routines (alphabetical) > Routines: X > XVOLUME_ROTATE

# XVOLUME_ROTATE

The XVOLUME_ROTATE procedure is used to programmatically rotate the volume currently displayed in XVOLUME. XVOLUME must be called prior to calling XVOLUME_ROTATE. This procedure can be used to create animations of volumes and isosurfaces.

This routine is written in the IDL language. Its source code can be found in the file `xvolume_rotate.pro` in the `lib/utilities` subdirectory of the IDL distribution.

## Examples

The following example creates an animation of the volume currently displayed in XVOLUME. It does this by rotating the volume through 360 degrees in increments of 10 degrees using XVOLUME_ROTATE, and writing the volume to a BMP file for each increment using XVOLUME_WRITE_IMAGE. It then loops through the images and uses TV to display each image.

First, display a volume as follows:

; Create a volume:
vol = BYTSCL(RANDOMU((SEED=0),5,5,5))
vol = CONGRID(vol, 30,30,30)
; Display volume:
XVOLUME, vol

Now, use the XVOLUME interface to modify the orientation and appearance of the volume or isosurface as desired. Once you have the volume or isosurface displayed the way you want it, run the following program. To try the example, save the following code in a file named `spin_volume.pro`, then compile and execute the procedure. (If you are viewing this topic in the IDL Workbench help, you can simply click on the code block below to compile the routine, then enter `spin_volume` at the IDL command line.)

PRO spin_volume
inc = 10. ; degrees.
; Create images
FOR i=0,(360./inc)-2 DO BEGIN
XVOLUME_WRITE_IMAGE, $
'spin' + STRCOMPRESS(i, /REMOVE_ALL) + '.bmp', 'bmp'
XVOLUME_ROTATE, [0,0,1], inc, /PREMULTIPLY
ENDFOR
XVOLUME_ROTATE, [0,0,1], inc, /PREMULTIPLY
; Read images
img = READ_BMP('spin0.bmp')
siz = SIZE(img, /DIM)
arr = BYTARR(3, siz[1], siz[2], 360./inc-1)
FOR i=0,360./inc-2 DO BEGIN
img = READ_BMP( $
'spin' + STRCOMPRESS(i, /REMOVE_ALL) + '.bmp', /RGB)
arr[0,0,0, i] = img
PRINT, i
ENDFOR
; Display animation
FOR i=0,2 DO BEGIN ; num rotations
FOR j=0,(360./inc)-2 DO BEGIN
TV, arr[*,*,*,j], /TRUE
ENDFOR
ENDFOR
TV, arr[*,*,*,0], /TRUE
END

## Syntax

XVOLUME_ROTATE, Axis, Angle [, /PREMULTIPLY]

## Arguments

### Axis

A 3-element vector of the form [x, y, z] describing the axis about which the model is to be rotated.

### Angle

The amount of rotation, measured in degrees.

## Keywords

### PREMULTIPLY

Set this keyword to cause the rotation matrix specified by Axis and Angle to be pre-multiplied to the model’s transformation matrix. By default, the rotation matrix is post-multiplied.

## Version History

5.4 | Introduced

## See Also

XVOLUME, XVOLUME_WRITE_IMAGE