Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def look(self, direction):
norm = get_norm(direction)
if norm == 0:
return
direction /= norm
self.purposeful_looking_direction = direction
for pupil, eye in zip(self.pupils.split(), self.eyes.split()):
c = eye.get_center()
right = eye.get_right() - c
up = eye.get_top() - c
vect = direction[0] * right + direction[1] * up
v_norm = get_norm(vect)
p_radius = 0.5 * pupil.get_width()
vect *= (v_norm - 0.75 * p_radius) / v_norm
pupil.move_to(c + vect)
self.pupils[1].align_to(self.pupils[0], DOWN)
return self
def look(self, direction):
norm = get_norm(direction)
if norm == 0:
return
direction /= norm
self.purposeful_looking_direction = direction
for pupil, eye in zip(self.pupils.split(), self.eyes.split()):
c = eye.get_center()
right = eye.get_right() - c
up = eye.get_top() - c
vect = direction[0] * right + direction[1] * up
v_norm = get_norm(vect)
p_radius = 0.5 * pupil.get_width()
vect *= (v_norm - 0.75 * p_radius) / v_norm
pupil.move_to(c + vect)
self.pupils[1].align_to(self.pupils[0], DOWN)
return self
def look(self, direction):
norm = get_norm(direction)
if norm == 0:
return
direction /= norm
self.purposeful_looking_direction = direction
for pupil, eye in zip(self.pupils.split(), self.eyes.split()):
c = eye.get_center()
right = eye.get_right() - c
up = eye.get_top() - c
vect = direction[0] * right + direction[1] * up
v_norm = get_norm(vect)
p_radius = 0.5 * pupil.get_width()
vect *= (v_norm - 0.75 * p_radius) / v_norm
pupil.move_to(c + vect)
self.pupils[1].align_to(self.pupils[0], DOWN)
return self
def get_length(self):
start, end = self.get_start_and_end()
return get_norm(start - end)
def get_3d_vmob_unit_normal(vmob, point_index):
n_points = vmob.get_num_points()
if len(vmob.get_anchors()) <= 2:
return np.array(UP)
i = point_index
im3 = i - 3 if i > 2 else (n_points - 4)
ip3 = i + 3 if i < (n_points - 3) else 3
unit_normal = get_unit_normal(
vmob.points[ip3] - vmob.points[i],
vmob.points[im3] - vmob.points[i],
)
if get_norm(unit_normal) == 0:
return np.array(UP)
return unit_normal
def get_vector_movement(self, func):
for v in self.moving_vectors:
v.target = Vector(func(v.get_end()), color=v.get_color())
norm = get_norm(v.target.get_end())
if norm < 0.1:
v.target.get_tip().scale_in_place(norm)
return self.get_piece_movement(self.moving_vectors)
def get_arc_length(self, n_sample_points=None):
if n_sample_points is None:
n_sample_points = 4 * self.get_num_curves() + 1
points = np.array([
self.point_from_proportion(a)
for a in np.linspace(0, 1, n_sample_points)
])
diffs = points[1:] - points[:-1]
norms = np.apply_along_axis(get_norm, 1, diffs)
return np.sum(norms)
rotate=False,
color=None,
label_scale_factor=VECTOR_LABEL_SCALE_FACTOR):
if not isinstance(label, TexMobject):
if len(label) == 1:
label = "\\vec{\\textbf{%s}}" % label
label = TexMobject(label)
if color is None:
color = vector.get_color()
label.set_color(color)
label.scale(label_scale_factor)
label.add_background_rectangle()
if at_tip:
vect = vector.get_vector()
vect /= get_norm(vect)
label.next_to(vector.get_end(), vect, buff=SMALL_BUFF)
else:
angle = vector.get_angle()
if not rotate:
label.rotate(-angle, about_point=ORIGIN)
if direction == "left":
label.shift(-label.get_bottom() + 0.1 * UP)
else:
label.shift(-label.get_top() + 0.1 * DOWN)
label.rotate(angle, about_point=ORIGIN)
label.shift((vector.get_end() - vector.get_start()) / 2)
return label
def set_tip_points(
self, tip,
add_at_end=True,
tip_length=None,
preserve_normal=True,
):
if tip_length is None:
tip_length = self.tip_length
if preserve_normal:
normal_vector = self.get_normal_vector()
else:
normal_vector = self.normal_vector
line_length = get_norm(self.points[-1] - self.points[0])
tip_length = min(
tip_length, self.max_tip_length_to_length_ratio * line_length
)
indices = (-2, -1) if add_at_end else (1, 0)
pre_end_point, end_point = [
self.get_anchors()[index]
for index in indices
]
vect = end_point - pre_end_point
perp_vect = np.cross(vect, normal_vector)
for v in vect, perp_vect:
if get_norm(v) == 0:
v[0] = 1
v *= tip_length / get_norm(v)
ratio = self.tip_width_to_length_ratio