#pragma rtGlobals=3 #pragma version = 2.0 #pragma IgorVersion = 6.1 #pragma ModuleName = PearlVectorOperations // author: matthias.muntwiler@psi.ch // Copyright (c) 2011-13 Paul Scherrer Institut // $Id$ function rotate2d_x(xx, yy, angle) // rotates a 2D cartesian vector and returns its x component variable xx, yy variable angle // rotation angle in degrees return xx * cos(angle * pi / 180) - yy * sin(angle * pi / 180) end function rotate2d_y(xx, yy, angle) // rotates a 2D cartesian vector and returns its y component variable xx, yy variable angle // rotation angle in degrees return xx * sin(angle * pi / 180) + yy * cos(angle * pi / 180) end function /wave create_rotation_matrix_free() // creates a matrix which represents a 3-vector rotation // the matrix is initialized as identity make /n=(3,3)/free matrix matrix = p == q // identity return matrix end function /wave set_rotation_x(matrix, angle) // calculates a matrix representing a 3-vector rotation around the x axis wave matrix // rotation matrix variable angle // rotation angle in degrees variable si = sin(angle * pi / 180) variable co = cos(angle * pi / 180) matrix[1][1] = co matrix[2][2] = co matrix[2][1] = si matrix[1][2] = -si return matrix end function /wave set_rotation_y(matrix, angle) // calculates a matrix representing a 3-vector rotation around the y axis wave matrix // rotation matrix variable angle // rotation angle in degrees variable si = sin(angle * pi / 180) variable co = cos(angle * pi / 180) matrix[0][0] = co matrix[2][2] = co matrix[0][2] = si matrix[2][0] = -si return matrix end function /wave set_rotation_z(matrix, angle) // calculates a matrix representing a 3-vector rotation around the z axis wave matrix // rotation matrix variable angle // rotation angle in degrees variable si = sin(angle * pi / 180) variable co = cos(angle * pi / 180) matrix[0][0] = co matrix[1][1] = co matrix[1][0] = si matrix[0][1] = -si return matrix end function rotate_x_wave(inout, angle) // rotates a wave of 3-vectors about the x axis wave inout // wave with dimensions (3, N), N >= 1, (x, y, z) // result will be in same wave variable angle // rotation angle in degrees wave m_rotation_x = create_rotation_matrix_free() make /n=3/d/free w_temp_rotate_x variable ivec, nvec nvec = max(DimSize(inout, 1), 1) for (ivec = 0; ivec < nvec; ivec += 1) set_rotation_x(m_rotation_x, angle) w_temp_rotate_x = inout[p][ivec] matrixop /free w_temp_rotate_x_result = m_rotation_x x w_temp_rotate_x inout[][ivec] = w_temp_rotate_x_result[p] endfor end function rotate_y_wave(inout, angle) // rotates a wave of 3-vectors about the y axis wave inout // wave with dimensions (3, N), N >= 1, (x, y, z) // result will be in same wave variable angle // rotation angle in degrees wave m_rotation_y = create_rotation_matrix_free() make /n=3/d/free w_temp_rotate_y variable ivec, nvec nvec = max(DimSize(inout, 1), 1) for (ivec = 0; ivec < nvec; ivec += 1) set_rotation_y(m_rotation_y, angle) w_temp_rotate_y = inout[p][ivec] matrixop /free w_temp_rotate_y_result = m_rotation_y x w_temp_rotate_y inout[][ivec] = w_temp_rotate_y_result[p] endfor end function rotate_z_wave(inout, angle) // rotates a wave of 3-vectors about the z axis wave inout // wave with dimensions (3, N), N >= 1, (x, y, z) // result will be in same wave variable angle // rotation angle in degrees wave m_rotation_z = create_rotation_matrix_free() make /n=3/d/free w_temp_rotate_z variable ivec, nvec nvec = max(DimSize(inout, 1), 1) for (ivec = 0; ivec < nvec; ivec += 1) set_rotation_z(m_rotation_z, angle) w_temp_rotate_z = inout[p][ivec] matrixop /free w_temp_rotate_z_result = m_rotation_z x w_temp_rotate_z inout[][ivec] = w_temp_rotate_z_result[p] endfor end