def _build_an_egg(power, tip_addon): h = lambda cos_alpha: cos_alpha * (1 - 1 / power) + 1 / ( power * cos_alpha) - (1 + tip_addon) cos_alpha_solution = fsolve(h, x0=.5)[0] if cos_alpha_solution > 1.: cos_alpha_solution = 1 / (cos_alpha_solution * (power - 1)) if is_the_same_point(1., cos_alpha_solution): a = 0 else: a = (1 + tip_addon - cos_alpha_solution) / ( (1 - cos_alpha_solution * cos_alpha_solution)**(power / 2)) alpha_solution = acos_hours(cos_alpha_solution) _arc = build_an_arc(angle_start=0, angle_end=full_turn_angle / 2 - alpha_solution) pf_points_qty = int(my_default_vertices_qty_in_circle / 4) power_func_x = sqrt(1 - cos_alpha_solution * cos_alpha_solution) * ( 1. - np.array([n / pf_points_qty for n in range(pf_points_qty + 1)])) power_func_2D = [[x, a * (x**power)] for x in power_func_x] right_half_contour = link_contours(_arc + [0, (1 + tip_addon)], power_func_2D) # adding the left half and # moving the egg so that its centre were where needed contour = add_a_left_mirror(right_half_contour) return contour
def build_a_sector(angle_start, angle_end, radius, radius_2=0): # make sure radius_1 >= radius_2 >= 0 if abs(radius) > abs(radius_2): radius, radius_2 = abs(radius), abs(radius_2) else: radius_2, radius = abs(radius), abs(radius_2) contour = build_an_arc(angle_start=angle_start, angle_end=angle_end) if is_the_same_point(radius_2, 0.0): # special case - just add the mid-point result = link_contours(contour, [[0, 0]]) * radius else: # add the arc inner_arc = np.ndarray.copy(contour) * radius_2 result = link_contours(contour * radius, inner_arc[::-1]) return result
def _build_an_arc(angle_start, angle_end): if angle_start > angle_end: angle_start, angle_end = angle_end, angle_start angle_start_normalized = angle_start / full_turn_angle angle_end_normalized = angle_end / full_turn_angle turn_nb_start = floor(angle_start_normalized) turn_nb_end = floor(angle_end_normalized) residual_start = ceil((angle_start_normalized - turn_nb_start) * my_default_vertices_qty_in_circle) residual_end = floor((angle_end_normalized - turn_nb_end) * my_default_vertices_qty_in_circle) if is_the_same_point(turn_nb_start, turn_nb_end): contour = sin_cos_std[residual_start:(residual_end + 1)] else: contour = sin_cos_std[residual_start:] + sin_cos_std * int( turn_nb_end - turn_nb_start - 1) + sin_cos_std[:(residual_end + 1)] contour = np.array(contour, np.float64) c_len = contour.size contour = link_contours([[sin_hours(angle_start), cos_hours(angle_start)]], contour) if c_len == contour.size: added_start = None else: added_start = residual_start - (angle_start_normalized % 1) * my_default_vertices_qty_in_circle c_len = contour.size contour = link_contours( contour, [[sin_hours(angle_end), cos_hours(angle_end)]]) if c_len == contour.size: added_end = None else: added_end = -residual_end + (angle_end_normalized % 1) * my_default_vertices_qty_in_circle return contour, added_start, added_end
def build_a_squiggle(angle_start, angle_end, speed_x, width, height): if angle_start > angle_end: angle_start, angle_end = angle_end, angle_start step = full_turn_angle / (max(abs(speed_x), 1) * my_default_vertices_qty_in_circle) angles = link_contours(np.arange(angle_start, angle_end, step), [angle_end]) contour = np.array([[sin_hours(a * speed_x), cos_hours(a)] for a in angles]) * [width / 2, height / 2] return contour
def build_a_heart(angle_top_middle, tip_addon): radius = 1 / (1 + sin_hours(angle_top_middle) ) # this ensures that the width = 2 a = sin_hours(angle_top_middle) * radius b = (1 + tip_addon) * radius c = sqrt(a * a + b * b) angle_bottom = atan_hours(a / b) + asin_hours(radius / c) # adding the right half-circle right_arc = build_an_arc( angle_start=full_turn_angle - angle_top_middle, angle_end=full_turn_angle * 1.25 + angle_bottom) * radius # moving the mid-point's x to 0 right_arc -= [right_arc[0, 0], 0] # adding the tip right_side = link_contours(right_arc, [[0, -radius * (1 + tip_addon)]]) # moving up so that the tip is in [0, 0] right_side += [0, +radius * (1 + tip_addon)] # adding up a left side contour = add_a_left_mirror(right_side) return contour
def build_a_crescent(width, depth_1, depth_2): smile1 = build_a_smile(width=width, depth=depth_1) smile2 = build_a_smile(width=width, depth=depth_2) result = link_contours(smile1, smile2[::-1]) return result