np.linalg.norm -> get_norm

This commit is contained in:
Grant Sanderson
2018-08-15 17:30:24 -07:00
parent f926611d34
commit 365093c0b5
82 changed files with 310 additions and 281 deletions

View File

@ -16,6 +16,7 @@ from utils.space_ops import angle_of_vector
from utils.space_ops import center_of_mass
from utils.space_ops import compass_directions
from utils.space_ops import rotate_vector
from utils.space_ops import get_norm
class Arc(VMobject):
@ -115,7 +116,7 @@ class ArcBetweenPoints(Arc):
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)
distance = get_norm(normal_vector)
normal_vector /= distance
if angle < 0:
normal_vector *= -1
@ -249,7 +250,7 @@ class AnnularSector(VMobject):
first_point = self.points[0]
last_point = self.points[-2]
v = last_point - first_point
radial_unit_vector = v / np.linalg.norm(v)
radial_unit_vector = v / get_norm(v)
arc_center = first_point - self.inner_radius * radial_unit_vector
return arc_center
@ -350,13 +351,13 @@ class Line(VMobject):
def get_length(self):
start, end = self.get_start_and_end()
return np.linalg.norm(start - end)
return get_norm(start - end)
def get_arc_length(self):
if self.path_arc:
anchors = self.get_anchors()
return sum([
np.linalg.norm(a2 - a1)
get_norm(a2 - a1)
for a1, a2 in zip(anchors, anchors[1:])
])
else:
@ -370,7 +371,7 @@ class Line(VMobject):
def get_unit_vector(self):
vect = self.get_vector()
norm = np.linalg.norm(vect)
norm = get_norm(vect)
if norm == 0:
# TODO, is this the behavior I want?
return np.array(ORIGIN)
@ -409,11 +410,11 @@ class Line(VMobject):
def put_start_and_end_on_with_projection(self, new_start, new_end):
target_vect = np.array(new_end) - np.array(new_start)
curr_vect = self.get_vector()
curr_norm = np.linalg.norm(curr_vect)
curr_norm = get_norm(curr_vect)
if curr_norm == 0:
self.put_start_and_end_on(new_start, new_end)
return
target_norm = np.linalg.norm(target_vect)
target_norm = get_norm(target_vect)
if target_norm == 0:
epsilon = 0.001
self.scale(epsilon / curr_norm)
@ -422,7 +423,7 @@ class Line(VMobject):
unit_target = target_vect / target_norm
unit_curr = curr_vect / curr_norm
normal = np.cross(unit_target, unit_curr)
if np.linalg.norm(normal) == 0:
if get_norm(normal) == 0:
if unit_curr[0] == 0 and unit_curr[1] == 0:
normal = UP
else:
@ -446,7 +447,7 @@ class DashedLine(Line):
Line.__init__(self, *args, **kwargs)
def generate_points(self):
length = np.linalg.norm(self.end - self.start)
length = get_norm(self.end - self.start)
if length == 0:
self.add(Line(self.start, self.end))
return self
@ -541,7 +542,7 @@ class Arrow(Line):
tip_base = center_of_mass(tip_base_points)
tbp1, tbp2 = tip_base_points
perp_vect = tbp2 - tbp1
tip_base_width = np.linalg.norm(perp_vect)
tip_base_width = get_norm(perp_vect)
if tip_base_width > 0:
perp_vect /= tip_base_width
width = min(
@ -573,7 +574,7 @@ class Arrow(Line):
normal_vector = self.get_normal_vector()
else:
normal_vector = self.normal_vector
line_length = np.linalg.norm(self.points[-1] - self.points[0])
line_length = get_norm(self.points[-1] - self.points[0])
tip_length = min(
tip_length, self.max_tip_length_to_length_ratio * line_length
)
@ -586,9 +587,9 @@ class Arrow(Line):
vect = end_point - pre_end_point
perp_vect = np.cross(vect, normal_vector)
for v in vect, perp_vect:
if np.linalg.norm(v) == 0:
if get_norm(v) == 0:
v[0] = 1
v *= tip_length / np.linalg.norm(v)
v *= tip_length / get_norm(v)
ratio = self.tip_width_to_length_ratio
tip.set_points_as_corners([
end_point,
@ -601,7 +602,7 @@ class Arrow(Line):
def get_normal_vector(self):
p0, p1, p2 = self.tip[0].get_anchors()
result = np.cross(p2 - p1, p1 - p0)
norm = np.linalg.norm(result)
norm = get_norm(result)
if norm == 0:
return self.normal_vector
else: