def init_parameters(self,start_angle, angle, arc_center, quad, ccw, **kwargs): if arc_center is None: if isinstance(start_angle, VMobject) and isinstance(angle, VMobject): self.tmp_center = line_intersection([start_angle.pts(0), start_angle.pts(-1)], [angle.pts(0), angle.pts(-1)]) else: self.tmp_center = ORIGIN elif isinstance(arc_center, (int, float)): if isinstance(start_angle, VMobject): self.tmp_center = start_angle.point_from_proportion(arc_center) else: raise Exception( "Invalid arc_center" ) else: self.tmp_center=arc_center if isinstance(start_angle, (VMobject)): start_angle = start_angle.get_direction() if quad==2 or quad==3: start_angle = (PI+start_angle)%TAU if isinstance(angle, (VMobject)): angle = angle.get_direction() if quad==3 or quad==4: angle = (PI+angle)%TAU if angle <= start_angle: angle = TAU+angle angle = angle-start_angle if not ccw: angle = -angle self.start_angle = start_angle self.angle = angle
def __init__(self, line, line_or_ratio=0, width=0.2, ccw=1, stroke_color=GRAY, reverse=False, *args, **kwargs): VGroup.__init__(self, **kwargs) if not isinstance(line, VGroup): angle = -ccw*PI/2 if reverse: width = -width if isinstance(line_or_ratio, (int, float)): pt0 = line.point_from_proportion(line_or_ratio) elif isinstance(line_or_ratio, (Mobject)): pt0 = line_intersection(line, line_or_ratio) else: pt0 = line_or_ratio self.add(SymElbow(line.get_line(1, pt0), width, ccw).set_color(stroke_color))
def get_arc_center(self): """ Looks at the normals to the first two anchors, and finds their intersection points """ # First two anchors and handles a1, h1, h2, a2 = self.points[:4] # Tangent vectors t1 = h1 - a1 t2 = h2 - a2 # Normals n1 = rotate_vector(t1, TAU / 4) n2 = rotate_vector(t2, TAU / 4) try: return line_intersection( line1=(a1, a1 + n1), line2=(a2, a2 + n2), ) except Exception: warnings.warn("Can't find Arc center, using ORIGIN instead") return np.array(ORIGIN)