def reset_points_by_anchors(self, anchors): # the num_of_up and bot anchors must fit: if not (self.num_of_anchor_in_bottom_curve + self.num_of_anchor_in_up_curve) == len(anchors): raise (Exception( "number of anchors must fit the attribute: num_of_anchor_in_bottom_curve & num_of_anchor_in_up_curve" )) #set up the up curve points: self.num_of_up_points = 3 * self.num_of_anchor_in_up_curve - 2 up_curve_points = np.zeros((self.num_of_up_points, self.dim)) h1, h2 = get_smooth_handle_points( anchors[0:self. num_of_anchor_in_up_curve]) # get smooth handles points up_curve_points[0] = anchors[0] arrays = [h1, h2, anchors[1:self.num_of_anchor_in_up_curve]] for index, array in enumerate(arrays): up_curve_points[index + 1::3] = array #set up the bot curve points: if self.set_up_the_bot_curve: self.number_of_bot_points = 3 * self.num_of_anchor_in_bottom_curve # +1多添加了一个点 bot_curve_points = np.zeros((self.number_of_bot_points, self.dim)) h1, h2 = get_smooth_handle_points( anchors[self.num_of_anchor_in_up_curve - 1:]) arrays = [h2, h1, anchors[self.num_of_anchor_in_up_curve:]] for index, array in enumerate(arrays): bot_curve_points[index + 0::3] = array #integrate whole points self.points = np.append(up_curve_points, bot_curve_points, axis=0) else: self.number_of_bot_points = 0 self.points = up_curve_points
def apply_function_to_points_smoothly(points, func, mean=0, std=1, about_point=ORIGIN): # this function takes care about the smootheness of each curve # the func is apply along y_axis( which means the input is x, output is y) #apply function to anchor points anchors = points[::3] anchors -= about_point anchors[:, 1] = func(anchors[:, 0], mean, std) # x to y, func's input is number not point anchors += about_point # get smooth handles points h1, h2 = get_smooth_handle_points(anchors) # insert anchors and handles accordingly points[0] = anchors[0] arrays = [h1, h2, anchors[1:]] for index, array in enumerate(arrays): points[index + 1::3] = array return points
def set_points_smoothly(self, points): if len(points) <= 1: return self points = self.prepare_new_anchor_points(points) h1, h2 = get_smooth_handle_points(points) self.set_anchors_and_handles(points, h1, h2) return self
def make_smooth(self): nppcc = self.n_points_per_cubic_curve subpaths = self.get_subpaths() self.clear_points() for subpath in subpaths: anchors = [*subpath[::nppcc], subpath[-1]] h1, h2 = get_smooth_handle_points(anchors) new_subpath = np.array(subpath) new_subpath[1::nppcc] = h1 new_subpath[2::nppcc] = h2 self.append_points(new_subpath) return self
def change_anchor_mode(self, mode): assert (mode in ["jagged", "smooth"]) nppc = self.n_points_per_curve for submob in self.family_members_with_points(): subpaths = submob.get_subpaths() submob.clear_points() for subpath in subpaths: anchors = np.vstack([subpath[::nppc], subpath[-1:]]) if mode == "smooth": h1, h2 = get_smooth_handle_points(anchors) new_subpath = get_quadratic_approximation_of_cubic( anchors[:-1], h1, h2, anchors[1:]) elif mode == "jagged": new_subpath = np.array(subpath) new_subpath[1::nppc] = interpolate(anchors[:-1], anchors[1:], 0.5) submob.append_points(new_subpath) submob.refresh_triangulation() return self
def change_anchor_mode(self, mode): assert (mode in ["jagged", "smooth"]) nppcc = self.n_points_per_cubic_curve for submob in self.family_members_with_points(): subpaths = submob.get_subpaths() submob.clear_points() for subpath in subpaths: anchors = np.append(subpath[::nppcc], subpath[-1:], 0) if mode == "smooth": h1, h2 = get_smooth_handle_points(anchors) elif mode == "jagged": a1 = anchors[:-1] a2 = anchors[1:] h1 = interpolate(a1, a2, 1.0 / 3) h2 = interpolate(a1, a2, 2.0 / 3) new_subpath = np.array(subpath) new_subpath[1::nppcc] = h1 new_subpath[2::nppcc] = h2 submob.append_points(new_subpath) return self
def change_anchor_mode(self, mode): assert(mode in ["jagged", "smooth"]) nppcc = self.n_points_per_cubic_curve for submob in self.family_members_with_points(): subpaths = submob.get_subpaths() submob.clear_points() for subpath in subpaths: anchors = np.append( subpath[::nppcc], subpath[-1:], 0 ) if mode == "smooth": h1, h2 = get_smooth_handle_points(anchors) elif mode == "jagged": a1 = anchors[:-1] a2 = anchors[1:] h1 = interpolate(a1, a2, 1.0 / 3) h2 = interpolate(a1, a2, 2.0 / 3) new_subpath = np.array(subpath) new_subpath[1::nppcc] = h1 new_subpath[2::nppcc] = h2 submob.append_points(new_subpath) return self