Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Arrow normal direction bug fix

Grant Sanderson1c4da1c4e7e9
diff --git a/bell.py b/bell.py
index c4fdee117..59d902e7d 100644
--- a/bell.py
+++ b/bell.py
@@ -126,13 +126,10 @@ class DirectionOfPolarization(FilterScene):
)
def continual_update(self):
+ reference_angle = self.reference_line.get_angle()
+ self.em_wave.rotation = reference_angle
FilterScene.continual_update(self)
- wave = self.em_wave.mobject
- angle = self.reference_line.get_angle()
- wave.rotate(
- angle, self.em_wave.propogation_direction,
- about_point = self.em_wave.start_point,
- )
+ vect_groups = [self.em_wave.E_vects, self.em_wave.M_vects]
if self.apply_filter:
filters = sorted(
self.pol_filters,
@@ -143,7 +140,7 @@ class DirectionOfPolarization(FilterScene):
)
for pol_filter in filters:
filter_x = pol_filter.get_center()[0]
- for vect_group, angle in (self.em_wave.E_vects, 0), (self.em_wave.M_vects, -np.pi/2):
+ for vect_group, angle in zip(vect_groups, [0, -np.pi/2]):
proj_vect = rotate_vector(
OUT, pol_filter.filter_angle + angle, RIGHT,
)
@@ -156,6 +153,8 @@ class DirectionOfPolarization(FilterScene):
if start[0] > filter_x:
vect.apply_matrix(proj_matrix)
vect.shift(start - vect.get_start())
+ vect.set_tip_points(vect.tip)
+ vect.set_rectangular_stem_points()
class PhotonPassesCompletelyOrNotAtAll(DirectionOfPolarization):
CONFIG = {
@@ -410,11 +409,11 @@ class SecondVideoWrapper(Scene):
class BasicsOfPolarization(DirectionOfPolarization):
def construct(self):
self.show_continual_wave()
- self.show_photons()
+ # self.show_photons()
def show_continual_wave(self):
em_wave = self.em_wave
- em_wave.M_vects.set_fill(opacity = 0.5)
+ # em_wave.M_vects.set_fill(opacity = 0.25)
title = TextMobject("Waves in the ``electromagnetic field''")
title.to_edge(UP)
@@ -1088,5 +1087,6 @@ class VennDiagramProofByContradiction(Scene):
+
diff --git a/topics/geometry.py b/topics/geometry.py
index 58b76c80a..1d5fce20e 100644
--- a/topics/geometry.py
+++ b/topics/geometry.py
@@ -231,7 +231,8 @@ class Arrow(Line):
tbp1, tbp2 = tip_base_points
perp_vect = tbp2 - tbp1
tip_base_width = np.linalg.norm(perp_vect)
- perp_vect /= tip_base_width
+ if tip_base_width > 0:
+ perp_vect /= tip_base_width
width = min(
self.rectangular_stem_width,
self.max_stem_width_to_tip_width_ratio*tip_base_width,
@@ -283,8 +284,8 @@ class Arrow(Line):
return self
def get_normal_vector(self):
- p1, p2, p3 = self.tip.get_anchors()
- result = np.cross(p2 - p1, p3 - p2)
+ p0, p1, p2 = self.tip.get_anchors()
+ result = np.cross(p2 - p1, p1 - p0)
norm = np.linalg.norm(result)
if norm == 0:
return self.normal_vector
@@ -306,7 +307,7 @@ 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)
+ self.set_tip_points(self.tip, preserve_normal = False)
self.set_rectangular_stem_points()
def scale(self, scale_factor, **kwargs):
diff --git a/waves.py b/waves.py
index 4a781d0ed..6db9d8963 100644
--- a/waves.py
+++ b/waves.py
@@ -117,10 +117,13 @@ class EMWave(ContinualAnimationGroup):
}
def __init__(self, **kwargs):
digest_config(self, kwargs)
- self.matrix_transform = np.dot(
- z_to_vector(self.propogation_direction),
- np.linalg.inv(z_to_vector(RIGHT)),
- )
+ if not all(self.propogation_direction == RIGHT):
+ self.matrix_transform = np.dot(
+ z_to_vector(self.propogation_direction),
+ np.linalg.inv(z_to_vector(RIGHT)),
+ )
+ else:
+ self.matrix_transform = None
vector_oscillations = []
self.E_vects = VGroup()
@@ -161,7 +164,8 @@ class EMWave(ContinualAnimationGroup):
def update_mobject(self, dt):
ContinualAnimationGroup.update_mobject(self, dt)
self.mobject.rotate(self.rotation, RIGHT)
- self.mobject.apply_matrix(self.matrix_transform)
+ if self.matrix_transform:
+ self.mobject.apply_matrix(self.matrix_transform)
self.mobject.shift(self.start_point)
class WavePacket(Animation):