Where does the spaceship go?

MATL, 76 75 bytes

FFF!3Xyj"FFT_FTFv4BvtFT_YStTF_YS3:"3$y!]6$Xh@'ULlDRr'4#mt?X)Y*}xxt1Z)b+w]]x

This works in current version (12.1.1) of the language.

Edit (April 4, 2016): The behaviour of function v has changed in release 15.0.0 of the language. To make the above code run, remove the first v and replace the second 3$v. The following link includes this modification.

Try it online!

Explanation

The state of the ship can be described in terms of two variables:

  • position: 3x1 vector
  • orientation: 3x3 matrix with the accumulated rotation, where "accumulated" means repeated matrix product.

A third variable would be the direction in which the ship is facing, but that's not needed, because it can be obtained as the initial direction (column vector [1;0;0]) times the current orientation; that is, the first column of the orientation.

These two state variables are kept on the stack, and are updated with each letter. Each of the letters ULlDRr multiplies the orientation matrix by one of the six rotation matrices to update the orientation. Letter F adds the current position plus the first column of the orientation matrix.

The six rotation matrices are created as follows: first is introduced directly; second and third are circular shifts of the previous one; and the remaining three are transposed versions of the others.

FFF!             % 3x1 vector [0;0;0]: initial position
3Xy              % 3x3 identity matrix: initial orientation
j                % input string
"                % for-each character in that string
  FFT_FTFv4Bv    %   rotation matrix for U: defined directly
  tFT_YS         %   rotation matrix for L: U circularly shifted to the left
  tTF_YS         %   rotation matrix for l: L circularly shifted down
  3:"            %   repeat three times
    3$y!         %     copy third matrix from top and transpose
  ]              %   end loop. This creates rotation matrices for D, R, r
  6$Xh           %   pack the 6 matrices in a cell array
  @              %   push current character from the input string
  'ULlDRr'4#m    %   this gives an index 0 for F, 1 for U, 2 for L, ..., 6 for r
  t?             %   if non-zero: update orientation
    X)           %     pick corresponding rotation matrix
    Y*           %     matrix product
  }              %   else: update position
    xx           %     delete twice (index and rotation matrix are not used here)
    t1Z)         %     duplicate orientation matrix and take its first column
    b+           %     move position vector to top and add
    w            %     swap the two top-most elements in stack
  ]              %   end if
]                % end for-each
x                % delete orientation matrix
                 % implicitly display position vector