37 max_dist_rad):
38 """Compute the squared differences for least squares fitting.
39
40 Given a flattened rotation matrix, one N point pattern and another N point
41 pattern to transform into to, compute the squared differences between the
42 points in the two patterns after the rotation.
43
44 Parameters
45 ----------
46 flattened_rot_matrix : `numpy.ndarray`, (9, )
47 A flattened array representing a 3x3 rotation matrix. The array is
48 flattened to comply with the API of scipy.optimize.least_squares.
49 Flattened elements are [[0, 0], [0, 1], [0, 2], [1, 0]...]
50 pattern_a : `numpy.ndarray`, (N, 3)
51 A array containing N, 3 vectors representing the objects we would like
52 to transform into the frame of pattern_b.
53 pattern_b : `numpy.ndarray`, (N, 3)
54 A array containing N, 3 vectors representing the reference frame we
55 would like to transform pattern_a into.
56 max_dist_rad : `float`
57 The maximum distance allowed from the pattern matching. This value is
58 used as the standard error for the resultant chi values.
59
60 Returns
61 -------
62 noralized_diff : `numpy.ndarray`, (9,)
63 Array of differences between the vectors representing of the source
64 pattern rotated into the reference frame and the converse. This is
65 used to minimize in a least squares fitter.
66 """
67
68 rot_matrix = flattened_rot_matrix.reshape((3, 3))
69
70 rot_pattern_a = np.dot(rot_matrix, pattern_a.transpose()).transpose()
71 diff_pattern_a_to_b = rot_pattern_a - pattern_b
72
73
74 return diff_pattern_a_to_b.flatten() / max_dist_rad
75
76