mirror of
https://github.com/3b1b/manim.git
synced 2025-08-31 17:08:32 +00:00
Poor mans merge
This commit is contained in:
parent
b9edafa942
commit
accef01040
1 changed files with 17 additions and 13 deletions
|
@ -484,7 +484,7 @@ class Arrow(Line):
|
|||
self.init_colors()
|
||||
|
||||
def init_tip(self):
|
||||
self.tip = self.add_tip()
|
||||
self.add_tip()
|
||||
|
||||
def add_tip(self, add_at_end = True):
|
||||
tip = VMobject(
|
||||
|
@ -497,13 +497,16 @@ class Arrow(Line):
|
|||
)
|
||||
self.set_tip_points(tip, add_at_end, preserve_normal = False)
|
||||
self.add(tip)
|
||||
if not hasattr(self, 'tip'):
|
||||
self.tip = []
|
||||
self.tip.append(tuple((tip, add_at_end)))
|
||||
return tip
|
||||
|
||||
def add_rectangular_stem(self):
|
||||
self.rect = Rectangle(
|
||||
stroke_width = 0,
|
||||
fill_color = self.tip.get_fill_color(),
|
||||
fill_opacity = self.tip.get_fill_opacity()
|
||||
fill_color = self.tip[0][0].get_fill_color(),
|
||||
fill_opacity = self.tip[0][0].get_fill_opacity()
|
||||
)
|
||||
self.add_to_back(self.rect)
|
||||
self.set_stroke(width = 0)
|
||||
|
@ -512,7 +515,7 @@ class Arrow(Line):
|
|||
def set_rectangular_stem_points(self):
|
||||
start, end = self.get_start_and_end()
|
||||
vect = end - start
|
||||
tip_base_points = self.tip.get_anchors()[1:]
|
||||
tip_base_points = self.tip[0][0].get_anchors()[1:]
|
||||
tip_base = center_of_mass(tip_base_points)
|
||||
tbp1, tbp2 = tip_base_points
|
||||
perp_vect = tbp2 - tbp1
|
||||
|
@ -536,8 +539,8 @@ class Arrow(Line):
|
|||
return self
|
||||
|
||||
def set_tip_points(
|
||||
self, tip,
|
||||
add_at_end = True,
|
||||
self, tip,
|
||||
add_at_end = True,
|
||||
tip_length = None,
|
||||
preserve_normal = True,
|
||||
):
|
||||
|
@ -565,7 +568,7 @@ class Arrow(Line):
|
|||
v *= tip_length/np.linalg.norm(v)
|
||||
ratio = self.tip_width_to_length_ratio
|
||||
tip.set_points_as_corners([
|
||||
end_point,
|
||||
end_point,
|
||||
end_point-vect+perp_vect*ratio/2,
|
||||
end_point-vect-perp_vect*ratio/2,
|
||||
])
|
||||
|
@ -573,7 +576,7 @@ class Arrow(Line):
|
|||
return self
|
||||
|
||||
def get_normal_vector(self):
|
||||
p0, p1, p2 = self.tip.get_anchors()
|
||||
p0, p1, p2 = self.tip[0][0].get_anchors()
|
||||
result = np.cross(p2 - p1, p1 - p0)
|
||||
norm = np.linalg.norm(result)
|
||||
if norm == 0:
|
||||
|
@ -587,7 +590,7 @@ class Arrow(Line):
|
|||
|
||||
def get_end(self):
|
||||
if hasattr(self, "tip"):
|
||||
return self.tip.get_anchors()[0]
|
||||
return self.tip[0][0].get_anchors()[0]
|
||||
else:
|
||||
return Line.get_end(self)
|
||||
|
||||
|
@ -596,14 +599,16 @@ class Arrow(Line):
|
|||
|
||||
def put_start_and_end_on(self, *args, **kwargs):
|
||||
Line.put_start_and_end_on(self, *args, **kwargs)
|
||||
self.set_tip_points(self.tip, preserve_normal = False)
|
||||
self.set_tip_points(self.tip[0][0], preserve_normal = False)
|
||||
self.set_rectangular_stem_points()
|
||||
return self
|
||||
|
||||
def scale(self, scale_factor, **kwargs):
|
||||
Line.scale(self, scale_factor, **kwargs)
|
||||
if self.preserve_tip_size_when_scaling:
|
||||
self.set_tip_points(self.tip)
|
||||
for t in self.tip:
|
||||
print(t)
|
||||
self.set_tip_points(t[0], add_at_end=t[1])
|
||||
if self.use_rectangular_stem:
|
||||
self.set_rectangular_stem_points()
|
||||
return self
|
||||
|
@ -623,8 +628,7 @@ class Vector(Arrow):
|
|||
|
||||
class DoubleArrow(Arrow):
|
||||
def init_tip(self):
|
||||
self.tip = self.add_tip()
|
||||
self.second_tip = self.add_tip(add_at_end = False)
|
||||
self.tip = [(self.add_tip(), True), (self.add_tip(add_at_end = False), False)]
|
||||
|
||||
class CubicBezier(VMobject):
|
||||
def __init__(self, points, **kwargs):
|
||||
|
|
Loading…
Add table
Reference in a new issue