mirror of
https://github.com/3b1b/manim.git
synced 2025-08-02 11:03:03 +08:00
classes ArcBetweenPoints, CurvedArrow, CurvedDoubleArrow
This makes it easier to draw arcs
This commit is contained in:
@ -96,6 +96,47 @@ class Arc(VMobject):
|
||||
|
||||
return self
|
||||
|
||||
|
||||
|
||||
class ArcBetweenPoints(Arc):
|
||||
|
||||
def __init__(self, start_point, end_point, angle = TAU/4, **kwargs):
|
||||
if angle == 0:
|
||||
raise Exception("Arc with zero curve angle. Use Line instead.")
|
||||
|
||||
midpoint = 0.5 * (start_point + end_point)
|
||||
distance_vector = end_point - start_point
|
||||
normal_vector = np.array([-distance_vector[1], distance_vector[0],0])
|
||||
distance = np.linalg.norm(normal_vector)
|
||||
normal_vector /= distance
|
||||
radius = distance/2 / np.sin(0.5 * angle)
|
||||
l = distance/2 / np.tan(0.5 * angle)
|
||||
arc_center = midpoint + l * normal_vector
|
||||
w = start_point - arc_center
|
||||
if w[0] != 0:
|
||||
start_angle = np.arctan(w[1]/w[0])
|
||||
else:
|
||||
start_angle = np.pi/2
|
||||
|
||||
Arc.__init__(self, angle,
|
||||
radius = radius,
|
||||
start_angle = start_angle,
|
||||
**kwargs)
|
||||
self.move_arc_center_to(arc_center)
|
||||
|
||||
class CurvedArrow(ArcBetweenPoints):
|
||||
|
||||
def __init__(self, start_point, end_point, angle = TAU/4, **kwargs):
|
||||
ArcBetweenPoints.__init__(self, start_point, end_point, angle = TAU/4, **kwargs)
|
||||
self.add_tip()
|
||||
|
||||
class CurvedDoubleArrow(ArcBetweenPoints):
|
||||
|
||||
def __init__(self, start_point, end_point, angle = TAU/4, **kwargs):
|
||||
ArcBetweenPoints.__init__(self, start_point, end_point, angle = TAU/4, **kwargs)
|
||||
self.add_tip(at_start = True, at_end = True)
|
||||
|
||||
|
||||
class Circle(Arc):
|
||||
CONFIG = {
|
||||
"color" : RED,
|
||||
|
Reference in New Issue
Block a user