88
99def angles2matrix (rot_z = 0 , rot_y = 0 , rot_x = 0 ):
1010 """
11- This method returns the rotation matrix for given rotations around z, y and x axes. The output rotation matrix is
12- equal to the composition of the individual rotations. Rotations are counter-clockwise .
13- The default value of the three rotations is zero.
11+ This method returns the rotation matrix for given rotations around z, y and x axes.
12+ The output rotation matrix is equal to the composition of the individual rotations.
13+ Rotations are counter-clockwise. The default value of the three rotations is zero.
1414
1515 :param float rot_z: rotation angle (in radians) around z-axis.
1616 :param float rot_y: rotation angle (in radians) around y-axis.
1717 :param float rot_x: rotation angle (in radians) around x-axis.
1818
1919 :return: rot_matrix: rotation matrix for the given angles. The matrix shape is always (3, 3).
20- :rtype: numpy.ndarray
21-
20+ :rtype: numpy.ndarray
21+
2222 :Example:
2323
2424 >>> import pygem.affine as at
2525 >>> import numpy as np
2626
27- >>> # Example of a rotation around x, y, z axis
27+ >>> # Example of a rotation around x, y, z axis
2828 >>> rotz = 10*np.pi/180
2929 >>> roty = 20*np.pi/180
3030 >>> rotx = 30*np.pi/180
3131 >>> rot_matrix = at.angles2matrix(rotz, roty, rotx)
32-
32+
3333 .. note::
3434
3535 - The direction of rotation is given by the right-hand rule.
3636 - When applying the rotation to a vector, the vector should be column vector
3737 to the right of the rotation matrix.
38-
3938 """
4039 rot_matrix = []
4140 if rot_z :
@@ -65,18 +64,17 @@ def to_reduced_row_echelon_form(matrix):
6564
6665 :return matrix: the reduced matrix.
6766 :rtype: matrix
68-
69-
67+
7068 :Example:
7169
7270 >>> import pygem.affine as at
7371
7472 >>> matrix = [[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]]
7573 >>> rref_matrix = at.to_reduced_row_echelon_form(matrix)
76-
74+
7775 .. note::
76+
7877 `matrix` will change after calling this function.
79-
8078 """
8179 lead = 0
8280 row_count = len (matrix )
@@ -138,8 +136,8 @@ def affine_points_fit(points_start, points_end):
138136 c = [[0.0 for a in range (dim )] for i in range (dim + 1 )]
139137 for j in range (dim ):
140138 for k in range (dim + 1 ):
141- for i in range ( len ( points_start ) ):
142- qt = list (points_start [ i ] ) + [1 ]
139+ for i , pnts_i in enumerate ( points_start ):
140+ qt = list (pnts_i ) + [1 ]
143141 c [k ][j ] += qt [k ] * points_end [i ][j ]
144142
145143 # Fill an an empty (dim+1) x (dim+1) matrix
@@ -152,11 +150,11 @@ def affine_points_fit(points_start, points_end):
152150
153151
154152 # Augement Q with c and get the reduced row echelon form of the result
155- M = [Q [i ] + c [i ] for i in range (dim + 1 )]
153+ affine_matrix = [Q [i ] + c [i ] for i in range (dim + 1 )]
156154
157- if np .linalg .cond (M ) < 1 / sys .float_info .epsilon :
158- rref_M = to_reduced_row_echelon_form (M )
159- rref_M = np .array (rref_M )
155+ if np .linalg .cond (affine_matrix ) < 1 / sys .float_info .epsilon :
156+ rref_aff_matrix = to_reduced_row_echelon_form (affine_matrix )
157+ rref_aff_matrix = np .array (rref_aff_matrix )
160158 else :
161159 raise RuntimeError ("Error: singular matrix. Points are probably coplanar." )
162160
@@ -173,9 +171,9 @@ def transform_vector(source):
173171 destination = np .zeros (dim )
174172 for i in range (dim ):
175173 for j in range (dim ):
176- destination [j ] += source [i ] * rref_M [i ][j + dim + 1 ]
174+ destination [j ] += source [i ] * rref_aff_matrix [i ][j + dim + 1 ]
177175 # Add the last line of the rref
178- destination [i ] += rref_M [dim ][i + dim + 1 ]
176+ destination [i ] += rref_aff_matrix [dim ][i + dim + 1 ]
179177 return destination
180178
181179 return transform_vector
0 commit comments