PEARL Procedures  rev-distro-1.6.0-0-gcf1399e-dirty
Igor procedures for the analysis of PEARL data
pearl-vector-operations.ipf
Go to the documentation of this file.
1 #pragma rtGlobals=3
2 #pragma version = 2.0
3 #pragma IgorVersion = 6.1
4 #pragma ModuleName = PearlVectorOperations
5 
6 // author: matthias.muntwiler@psi.ch
7 // Copyright (c) 2011-13 Paul Scherrer Institut
8 // $Id$
9 
10 variable rotate2d_x(variable xx, variable yy, variable angle){
11  // rotates a 2D cartesian vector and returns its x component
12  variable xx, yy
13  variable angle// rotation angle in degrees
14 
15  return xx * cos(angle * pi / 180) - yy * sin(angle * pi / 180)
16 };
17 
18 variable rotate2d_y(variable xx, variable yy, variable angle){
19  // rotates a 2D cartesian vector and returns its y component
20  variable xx, yy
21  variable angle// rotation angle in degrees
22 
23  return xx * sin(angle * pi / 180) + yy * cos(angle * pi / 180)
24 };
25 
27  // creates a matrix which represents a 3-vector rotation
28  // the matrix is initialized as identity
29 
30  make /n=(3,3)/free matrix
31  matrix = p == q// identity
32  return matrix
33 };
34 
35 wave set_rotation_x(wave matrix, variable angle){
36  // calculates a matrix representing a 3-vector rotation around the x axis
37  wave matrix// rotation matrix
38  variable angle// rotation angle in degrees
39 
40  variable si = sin(angle * pi / 180)
41  variable co = cos(angle * pi / 180)
42 
43  matrix[1][1] = co
44  matrix[2][2] = co
45  matrix[2][1] = si
46  matrix[1][2] = -si
47 
48  return matrix
49 };
50 
51 wave set_rotation_y(wave matrix, variable angle){
52  // calculates a matrix representing a 3-vector rotation around the y axis
53  wave matrix// rotation matrix
54  variable angle// rotation angle in degrees
55 
56  variable si = sin(angle * pi / 180)
57  variable co = cos(angle * pi / 180)
58 
59  matrix[0][0] = co
60  matrix[2][2] = co
61  matrix[0][2] = si
62  matrix[2][0] = -si
63 
64  return matrix
65 };
66 
67 wave set_rotation_z(wave matrix, variable angle){
68  // calculates a matrix representing a 3-vector rotation around the z axis
69  wave matrix// rotation matrix
70  variable angle// rotation angle in degrees
71 
72  variable si = sin(angle * pi / 180)
73  variable co = cos(angle * pi / 180)
74 
75  matrix[0][0] = co
76  matrix[1][1] = co
77  matrix[1][0] = si
78  matrix[0][1] = -si
79 
80  return matrix
81 };
82 
83 variable rotate_x_wave(wave inout, variable angle){
84  // rotates a wave of 3-vectors about the x axis
85  wave inout// wave with dimensions (3, N), N >= 1, (x, y, z)
86  // result will be in same wave
87  variable angle// rotation angle in degrees
88 
89  wave m_rotation_x = create_rotation_matrix_free()
90  make /n=3/d/free w_temp_rotate_x
91  variable ivec, nvec
92  nvec = max(DimSize(inout, 1), 1)
93  for (ivec = 0; ivec < nvec; ivec += 1)
94  set_rotation_x(m_rotation_x, angle)
95  w_temp_rotate_x = inout[p][ivec]
96  matrixop /free w_temp_rotate_x_result = m_rotation_x x w_temp_rotate_x
97  inout[][ivec] = w_temp_rotate_x_result[p]
98  endfor
99 };
100 
101 variable rotate_y_wave(wave inout, variable angle){
102  // rotates a wave of 3-vectors about the y axis
103  wave inout// wave with dimensions (3, N), N >= 1, (x, y, z)
104  // result will be in same wave
105  variable angle// rotation angle in degrees
106 
107  wave m_rotation_y = create_rotation_matrix_free()
108  make /n=3/d/free w_temp_rotate_y
109  variable ivec, nvec
110  nvec = max(DimSize(inout, 1), 1)
111  for (ivec = 0; ivec < nvec; ivec += 1)
112  set_rotation_y(m_rotation_y, angle)
113  w_temp_rotate_y = inout[p][ivec]
114  matrixop /free w_temp_rotate_y_result = m_rotation_y x w_temp_rotate_y
115  inout[][ivec] = w_temp_rotate_y_result[p]
116  endfor
117 };
118 
119 variable rotate_z_wave(wave inout, variable angle){
120  // rotates a wave of 3-vectors about the z axis
121  wave inout// wave with dimensions (3, N), N >= 1, (x, y, z)
122  // result will be in same wave
123  variable angle// rotation angle in degrees
124 
125  wave m_rotation_z = create_rotation_matrix_free()
126  make /n=3/d/free w_temp_rotate_z
127  variable ivec, nvec
128  nvec = max(DimSize(inout, 1), 1)
129  for (ivec = 0; ivec < nvec; ivec += 1)
130  set_rotation_z(m_rotation_z, angle)
131  w_temp_rotate_z = inout[p][ivec]
132  matrixop /free w_temp_rotate_z_result = m_rotation_z x w_temp_rotate_z
133  inout[][ivec] = w_temp_rotate_z_result[p]
134  endfor
135 };
136 
wave set_rotation_x(wave matrix, variable angle)
variable rotate_x_wave(wave inout, variable angle)
variable rotate2d_x(variable xx, variable yy, variable angle)
wave set_rotation_z(wave matrix, variable angle)
variable rotate_y_wave(wave inout, variable angle)
variable rotate2d_y(variable xx, variable yy, variable angle)
variable rotate_z_wave(wave inout, variable angle)
wave create_rotation_matrix_free()
wave set_rotation_y(wave matrix, variable angle)