def apply_transposed_matrix(self, transposed_matrix, **kwargs): func = self.get_transposed_matrix_transformation(transposed_matrix) if "path_arc" not in kwargs: net_rotation = np.mean([ angle_of_vector(func(RIGHT)), angle_of_vector(func(UP)) - np.pi / 2 ]) kwargs["path_arc"] = net_rotation self.apply_function(func, **kwargs)
def apply_transposed_matrix(self, transposed_matrix, **kwargs): func = self.get_matrix_transformation(transposed_matrix) if "path_arc" not in kwargs: net_rotation = np.mean([ angle_of_vector(func(RIGHT)), angle_of_vector(func(UP)) - np.pi / 2 ]) kwargs["path_arc"] = net_rotation self.apply_function(func, **kwargs)
def position_endpoints_on(self, start, end): curr_vect = self.points[-1] - self.points[0] if np.all(curr_vect == 0): raise Exception("Cannot position endpoints of closed loop") target_vect = end - start self.scale(np.linalg.norm(target_vect) / np.linalg.norm(curr_vect)) self.rotate(angle_of_vector(target_vect) - angle_of_vector(curr_vect)) self.shift(start - self.points[0]) return self
def position_endpoints_on(self, start, end): curr_vect = self.points[-1] - self.points[0] if np.all(curr_vect == 0): raise Exception("Cannot position endpoints of closed loop") target_vect = end - start self.scale(np.linalg.norm(target_vect) / np.linalg.norm(curr_vect)) self.rotate( angle_of_vector(target_vect) - angle_of_vector(curr_vect) ) self.shift(start - self.points[0]) return self
def position_endpoints_on(self, start, end): if any(self.points[:, 2]): raise RuntimeError("Mobject.position_endpoints_on() does not work " "with Mobjects that have depth") curr_vect = self.points[-1] - self.points[0] if np.all(curr_vect == 0): raise Exception("Cannot position endpoints of closed loop") target_vect = end - start self.scale(get_norm(target_vect) / get_norm(curr_vect)) self.rotate( angle_of_vector(target_vect) - angle_of_vector(curr_vect) ) self.shift(start - self.points[0]) return self
def __init__(self, **kwargs): Axes.__init__(self, **kwargs) z_axis = self.z_axis = self.get_axis(self.z_min, self.z_max, self.z_axis_config) z_axis.rotate(-np.pi / 2, UP, about_point=ORIGIN) z_axis.rotate(angle_of_vector(self.z_normal), OUT, about_point=ORIGIN) self.add(z_axis) self.add_3d_pieces() self.set_axis_shading()
def __init__(self, **kwargs): VGroup.__init__(self, **kwargs) self.x_axis = self.get_axis(self.x_min, self.x_max, self.x_axis_config) self.y_axis = self.get_axis(self.y_min, self.y_max, self.y_axis_config) self.y_axis.rotate(np.pi / 2, about_point=ORIGIN) self.add(self.x_axis, self.y_axis) if self.three_d: self.z_axis = self.get_axis(self.z_min, self.z_max, self.z_axis_config) self.z_axis.rotate(-np.pi / 2, UP, about_point=ORIGIN) self.z_axis.rotate(angle_of_vector(self.z_normal), OUT, about_point=ORIGIN) self.add(self.z_axis)
def __init__(self, **kwargs): VGroup.__init__(self, **kwargs) self.x_axis = self.get_axis(self.x_min, self.x_max, self.x_axis_config) self.y_axis = self.get_axis(self.y_min, self.y_max, self.y_axis_config) self.y_axis.rotate(np.pi / 2, about_point=ORIGIN) self.add(self.x_axis, self.y_axis) if self.three_d: self.z_axis = self.get_axis( self.z_min, self.z_max, self.z_axis_config) self.z_axis.rotate(-np.pi / 2, UP, about_point=ORIGIN) self.z_axis.rotate( angle_of_vector(self.z_normal), OUT, about_point=ORIGIN ) self.add(self.z_axis)
def display_image_mobject(self, image_mobject): corner_coords = self.points_to_pixel_coords(image_mobject.points) ul_coords, ur_coords, dl_coords = corner_coords right_vect = ur_coords - ul_coords down_vect = dl_coords - ul_coords center_coords = ul_coords + (right_vect + down_vect) / 2 sub_image = Image.fromarray( image_mobject.get_pixel_array(), mode="RGBA" ) # Reshape pixel_width = int(pdist([ul_coords, ur_coords])) pixel_height = int(pdist([ul_coords, dl_coords])) sub_image = sub_image.resize( (pixel_width, pixel_height), resample=Image.BICUBIC ) # Rotate angle = angle_of_vector(right_vect) adjusted_angle = -int(360 * angle / TAU) if adjusted_angle != 0: sub_image = sub_image.rotate( adjusted_angle, resample=Image.BICUBIC, expand=1 ) # TODO, there is no accounting for a shear... # Paste into an image as large as the camear's pixel array full_image = Image.fromarray( np.zeros((self.get_pixel_height(), self.get_pixel_width())), mode="RGBA" ) new_ul_coords = center_coords - np.array(sub_image.size) / 2 full_image.paste( sub_image, box=( new_ul_coords[0], new_ul_coords[1], new_ul_coords[0] + sub_image.size[0], new_ul_coords[1] + sub_image.size[1], ) ) # Paint on top of existing pixel array self.overlay_PIL_image(full_image)
def display_image_mobject(self, image_mobject, pixel_array): corner_coords = self.points_to_pixel_coords(image_mobject, image_mobject.points) ul_coords, ur_coords, dl_coords = corner_coords right_vect = ur_coords - ul_coords down_vect = dl_coords - ul_coords center_coords = ul_coords + (right_vect + down_vect) / 2 sub_image = Image.fromarray(image_mobject.get_pixel_array(), mode="RGBA") # Reshape pixel_width = max(int(pdist([ul_coords, ur_coords])), 1) pixel_height = max(int(pdist([ul_coords, dl_coords])), 1) sub_image = sub_image.resize((pixel_width, pixel_height), resample=Image.BICUBIC) # Rotate angle = angle_of_vector(right_vect) adjusted_angle = -int(360 * angle / TAU) if adjusted_angle != 0: sub_image = sub_image.rotate(adjusted_angle, resample=Image.BICUBIC, expand=1) # TODO, there is no accounting for a shear... # Paste into an image as large as the camear's pixel array full_image = Image.fromarray(np.zeros( (self.get_pixel_height(), self.get_pixel_width())), mode="RGBA") new_ul_coords = center_coords - np.array(sub_image.size) / 2 new_ul_coords = new_ul_coords.astype(int) full_image.paste(sub_image, box=( new_ul_coords[0], new_ul_coords[1], new_ul_coords[0] + sub_image.size[0], new_ul_coords[1] + sub_image.size[1], )) # Paint on top of existing pixel array self.overlay_PIL_image(pixel_array, full_image)
def get_angle(self): start, end = self.get_start_and_end() return angle_of_vector(end - start)
def angle_of_tangent(self, x, graph, dx=0.01): vect = self.input_to_graph_point( x + dx, graph) - self.input_to_graph_point(x, graph) return angle_of_vector(vect)
def get_needle_angle(self): return angle_of_vector( self.get_needle_tip() - self.get_center() )