def test_rotation_matrix(): sample_count = 10 vec_len_range = 10000 theta_range = pi # if > pi, may cause test fail, but don't worry. tol = 1e-4 for i in xrange(sample_count): axis_dir = random_vec(vec_len_range) vec_to_rotate = random_vec(vec_len_range) theta = random_float(theta_range) mat = rotation_array(theta, axis_dir) rotated_vec = mat.dot(vec_to_rotate) rotated_vec2 = mat.dot(rotated_vec) act_theta = intersec_angle(projection_to_plan(vec_to_rotate, axis_dir), projection_to_plan(rotated_vec, axis_dir)) act_theta *= cmp(np.dot(np.cross(vec_to_rotate, rotated_vec), axis_dir), 0) feqok_(act_theta, theta, tol) if theta < pi * tol: continue feqok_(vec_len(vec_to_rotate), vec_len(rotated_vec), tol) (r, center) = circum(vec_to_rotate, rotated_vec, rotated_vec2) feqok_(vec_len(np.cross(center, axis_dir)), 0, tol * max(vec_len(axis_dir), vec_len(center))) ok_(cmp(np.dot(center, axis_dir), 0) == cmp(np.dot(vec_to_rotate, axis_dir), 0))
def _search_root_on_plane(self, p_init, plane_norm, normed=True): # MARK: alpha_n_assuming see also self.edge_polygon # in Cermak2005 it is not directly presented # that grd should in the circle plan, # but the Neighborhood test in S7.1 assumed that. if not normed: plane_norm = norm_vec(plane_norm) grd = self.func_gd(p_init) grd = projection_to_plan(grd, plane_norm) func_val = self.func(p_init) delta = self.line_search_dlt * -cmp(func_val, 0) delta = delta * grd pnew2 = p_init + delta func_val2 = self.func(pnew2) pnew = p_init while func_val * func_val2 > 0: pnew = pnew2 pnew2 = pnew + delta func_val = func_val2 func_val2 = self.func(pnew2) rslt = brentq(lambda t: self.func(pnew * (1 - t) + pnew2 * t), 0, 1) pnew = pnew * (1 - rslt) + pnew2 * rslt return pnew