From 4e77f217f276a9811efd968f47d78701aaf61676 Mon Sep 17 00:00:00 2001 From: Somnath Pandit Date: Fri, 10 Jul 2020 00:41:24 +0530 Subject: checkpoint vector line int --- .../line-integrals/README.md | 6 +- .../line-integrals/file4_helix.py | 245 ------------------ .../line-integrals/file4_vector_line_integral.py | 282 +++++++++++++++++++++ .../line-integrals/file5_helix.py | 245 ++++++++++++++++++ .../line-integrals/gifs/file4_helix.gif | Bin 1237895 -> 0 bytes .../gifs/file4_vector_line_integral.gif | Bin 0 -> 1304411 bytes .../line-integrals/gifs/file5_helix.gif | Bin 0 -> 1237895 bytes .../unfinished_vector_line_integral.py | 282 --------------------- 8 files changed, 531 insertions(+), 529 deletions(-) delete mode 100644 FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file4_helix.py create mode 100644 FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file4_vector_line_integral.py create mode 100644 FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file5_helix.py delete mode 100644 FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file4_helix.gif create mode 100644 FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file4_vector_line_integral.gif create mode 100644 FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file5_helix.gif delete mode 100644 FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/unfinished_vector_line_integral.py (limited to 'FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals') diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/README.md b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/README.md index d93df26..14d95bd 100644 --- a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/README.md +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/README.md @@ -8,6 +8,8 @@ **file3_vector_line_int_as_sum** ![file3_vector_line_int_as_sum](gifs/file3_vector_line_int_as_sum.gif) +**file4_vector_line_integral** +![file4_vector_line_integral](gifs/file4_vector_line_integral) -**file4_helix** -![file4_helix](gifs/file4_helix.gif) +**file5_helix** +![file5_helix](gifs/file5_helix.gif) diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file4_helix.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file4_helix.py deleted file mode 100644 index 50aeb33..0000000 --- a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file4_helix.py +++ /dev/null @@ -1,245 +0,0 @@ -from manimlib.imports import * - -class ParametricCurve(ThreeDScene): - - CONFIG = { - "axes_config": { - "x_min": 0, - "x_max": 3, - "y_min": 0, - "y_max": 3, - "z_min": 0, - "z_max": 4, - "a":0 ,"b": 2, "c":0 , "d":2, - "axes_shift":2*IN+1.4*RIGHT+1.4*DOWN, - "x_axis_config": { - "tick_frequency": 1, - "include_tip": False, - }, - "y_axis_config": { - "tick_frequency": 1, - "include_tip": False, - }, - "z_axis_config": { - "tick_frequency": 1, - # "include_tip": False, - }, - }, - - } - - - def construct(self): - - self.setup_axes() - - self.set_camera_orientation( - distance=25, - phi=60 * DEGREES, - theta=40 * DEGREES, - ) - - label=TextMobject("Helix",color=PURPLE).scale(1.6) - label.to_corner(UR,buff=2) - self.add_fixed_in_frame_mobjects(label) - - helix=self.get_helix( - radius=1.5, - t_min= 0, - t_max= 4*PI, - color=PURPLE - ) - parameter_label=TextMobject( - "Parametric equation: ", - color=TEAL - ).next_to(label,DOWN,buff=.3 - ) - parametric_eqn=TextMobject( - "$x=\cos$ (","t", - r")\\$y=\sin $(","t", - r")\\$z$=","t" - ).next_to(parameter_label,DOWN,buff=.1) - parametric_eqn.set_color_by_tex("t",RED) - self.parametric_eqn=parametric_eqn - - parametriztion=VGroup( - parameter_label, - parametric_eqn - ) - - - self.play(ShowCreation(helix),run_time=2) - self.begin_ambient_camera_rotation(.1) - self.wait(1) - self.add_fixed_in_frame_mobjects(parametriztion) - self.play(Write(parametriztion)) - self.wait(1) - self.stop_ambient_camera_rotation() - self.move_camera( - distance=20, - phi=85 * DEGREES, - # theta=-90 * DEGREES, - run_time=3 - ) - scale_axes=VGroup(self.axes,helix).scale(1.2) - self.show_the_parameter() - self.wait(2) - - - - def get_helix(self,radius=1, **kwargs): - config = { - "t_min": 0, - "t_max": 2*PI, - } - config.update(kwargs) - helix= ParametricFunction( - lambda t : self.axes.c2p( - radius*np.cos(t), - radius*np.sin(t), - t/4 - ), - **config - ) - - self.helix=helix - return helix - - def show_the_parameter(self): - t_tracker = ValueTracker(0) - t=t_tracker.get_value - - t_label = TexMobject( - "t = ",color=RED - ).next_to(self.parametric_eqn,DL,buff=.85) - - t_text = always_redraw( - lambda: DecimalNumber( - t(), - color=GOLD, - ).next_to(t_label, RIGHT, MED_SMALL_BUFF) - ) - t_text.suspend_updating() - - dot = Sphere( - radius= 1.5*DEFAULT_DOT_RADIUS, - stroke_width= 1, - fill_opacity= 1.0, - ) - dot.set_color(GOLD) - dot.add_updater(lambda v: v.move_to( - self.helix.get_point_from_function(PI*t()) - )) - - pi = TexMobject( - "\\pi ", - color=GOLD, - ).next_to(t_text,RIGHT,buff=-.3) - - group = VGroup(t_text,t_label,pi).scale(1.5) - - self.wait(1) - self.add_fixed_in_frame_mobjects(group) - t_text.resume_updating() - self.play(FadeIn(group)) - self.add(dot) - self.play( - t_tracker.set_value,2, - rate_func=linear, - run_time=5 - ) - - -#-------------------------------------------------------- - - #customize 3D axes - def get_three_d_axes(self, include_labels=True, include_numbers=False, **kwargs): - config = dict(self.axes_config) - config.update(kwargs) - axes = ThreeDAxes(**config) - axes.set_stroke(width=1.5) - - if include_numbers: - self.add_axes_numbers(axes) - - if include_labels: - self.add_axes_labels(axes) - - # Adjust axis orientation - axes.x_axis.rotate( - 90 * DEGREES, LEFT, - about_point=axes.c2p(0, 0, 0), - ) - axes.y_axis.rotate( - 90 * DEGREES, UP, - about_point=axes.c2p(0, 0, 0), - ) - - - return axes - - - def setup_axes(self): - axes = self.get_three_d_axes(include_labels=True) - axes.scale(1) - # axes.center() - axes.shift(axes.axes_shift) - self.add(axes) - self.axes = axes - - def add_axes_numbers(self, axes): - x_axis = axes.x_axis - y_axis = axes.y_axis - tex_vals_x = [ - ("1", axes.b), - ] - tex_vals_y=[ - ("1", axes.d) - ] - x_labels = VGroup() - y_labels = VGroup() - for tex, val in tex_vals_x: - label = TexMobject(tex) - label.scale(1) - label.next_to(x_axis.n2p(val), DOWN) - label.rotate(180 * DEGREES) - x_labels.add(label) - x_axis.add(x_labels) - x_axis.numbers = x_labels - - for tex, val in tex_vals_y: - label = TexMobject(tex) - label.scale(1) - label.next_to(y_axis.n2p(val), LEFT) - label.rotate(90 * DEGREES) - y_labels.add(label) - - y_axis.add(y_labels) - y_axis.numbers = y_labels - - return axes - - def add_axes_labels(self, axes): - x_label = TexMobject("x") - x_label.next_to(axes.x_axis.get_end(), RIGHT) - axes.x_axis.label = x_label - - y_label = TextMobject("y") - y_label.rotate(90 * DEGREES, OUT) - y_label.next_to(axes.y_axis.get_end(), UP) - axes.y_axis.label = y_label - - z_label = TextMobject("z") - z_label.rotate(90 * DEGREES, LEFT) - z_label.next_to(axes.z_axis.get_zenith(), LEFT) - axes.z_axis.label = z_label - for axis in axes: - axis.add(axis.label) - return axes - - #uploaded by Somnath Pandit.FSF2020_Line_integrals - - - - - diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file4_vector_line_integral.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file4_vector_line_integral.py new file mode 100644 index 0000000..d5dda1f --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file4_vector_line_integral.py @@ -0,0 +1,282 @@ +from manimlib.imports import * + +class LineIntegrationProcess(GraphScene): + + CONFIG = { + "x_min" : -0, + "x_max" : 1, + "y_min" : -0, + "y_max" : 1, + "axes_color":WHITE, + "graph_origin": ORIGIN+6.5*LEFT+3*DOWN, + "x_axis_width": 6, + "y_axis_height": 6, + "x_tick_frequency": 1, + "y_tick_frequency": 1, + "default_vector_field_config": { + "delta_x": .5, + "delta_y": .5, + "min_magnitude": 0, + "max_magnitude": 15, + "colors": [BLUE], + "length_func": lambda norm : norm/35, + "opacity": 1.0, + "vector_config": { + "stroke_width":2 + }, + }, + "default_graph_style": { + "stroke_width": 2, + "stroke_color": WHITE, + }, + } + + + def construct(self): + X = RIGHT*self.x_axis_width/(self.x_max- self.x_min) + Y = UP*self.y_axis_height/(self.y_max- self.y_min) + self.X=X ;self.Y=Y + + self.setup_axes(animate=False) + + fn_text=TexMobject( + r"\vec F = x^2\hat i-xy\hat j", + stroke_width=2.5 + ).set_color_by_gradient( + *self.default_vector_field_config["colors"] + ) + fn_text.to_corner(UR,buff=.8).shift(2*LEFT) + + origin=self.graph_origin + v_field=self.get_vector_field( + lambda v: np.array([ + (v[0]-origin[0])**2, + -(v[0]-origin[0])*(v[1]-origin[1]), + 0, + ]), + x_min= -.001+origin[0], + x_max= 5.8+origin[0], + y_min= -0+origin[1], + y_max= 6.+origin[1], + ) + + # self.play(Write(surface)) + # self.play(Write(v_field),Write(fn_text)) + self.add(v_field, fn_text) + self.get_line_of_int() + self.get_dot_product_values() + '''self.get_field_values_on_line() + self.wait(1.5) + + self.remove(surface) + self.trasform_to_graphs()''' + self.wait(2) + + + def get_vector_field(self,func,**kwargs): + config = dict() + config.update(self.default_vector_field_config) + config.update(kwargs) + vector_field= VectorField(func,**config) + self.vector_field=vector_field + + return vector_field + + def get_line_of_int(self): + line_of_int_text=TextMobject(r"Line of integration is\\","$\\vec r(t)=\cos(t)\hat i+\sin(t)\hat j$") + line_of_int_text[1].set_color(PINK) + line_of_int_text.to_edge(TOP,buff=SMALL_BUFF) + + + line_of_int= self.get_graph( + lambda x : np.sqrt(1-x**2), + x_min=1, + x_max=0, + ) + line_of_int.set_style( + stroke_width=3, + stroke_color=PINK, + ) + + # self.play(Write(line_of_int_text)) + self.wait(.5) + # self.play(ShowCreation(line_of_int),run_time=1.5) + self.add(line_of_int) + + self.line_of_int=line_of_int + self.line_of_int_text=line_of_int_text + + def get_dot_product_values(self): + t_tracker = ValueTracker(0) + self.t_tracker = t_tracker + self.get_vector_and_tangent() + self.get_dot_product_graph() + self.wait(1.5) + self.play(ApplyMethod( + self.t_tracker.set_value, PI/2, + rate_func=linear, + run_time=2, + ) + ) + + def get_dot_product_graph(self): + pass + + + def get_vector_and_tangent(self): + self.play(FadeOut(self.axes)) + self.show_vector() + self.show_tangent() + + + def show_vector(self): + t = self.t_tracker.get_value + vect_label=TextMobject( + "$\\vec F(x_i,y_i)$", + color=YELLOW, + stroke_width=2 + ).scale(.8) + + vector = always_redraw( lambda: + self.vector_field.get_vector( + self.coords_to_point( + np.cos(t()), np.sin(t()) + ), + stroke_width=6, + max_stroke_width_to_length_ratio= 8, + ).set_color(YELLOW), + ) + vector.set_color(ORANGE) + vect_label.next_to(vector,RIGHT,buff=.1) + self.add(vector,vect_label) + # self.play(Write(vector),run_time=.2) + + self.vect_label = vect_label + + def show_tangent(self): + tangent_label=TextMobject("$\\vec T(x_i,y_i)$",color="#DC75CD",stroke_width=2).scale(.8) + + t = self.t_tracker.get_value + + tangent = always_redraw(lambda: + Vector( + color="#DC75CD", + stroke_width=6, + ).scale(1).next_to( + self.coords_to_point( + np.cos(t()), np.sin(t()) + ),DR,buff=-.1 + ).rotate( + self.angle_of_tangent( + np.cos(t()), + self.line_of_int, + dx=-0.00001 + ), + about_point=self.coords_to_point( + np.cos(t()), np.sin(t()) + ) + ) + ) + tangent_label.next_to(tangent,UP,buff=.1) + self.play(Write(VGroup(tangent,tangent_label))) + + self.tangent_label=tangent_label + + def dot_product(self): + + dot_sym=Dot().next_to(self.func_val,RIGHT) + + self.play(FadeOut(VGroup( + self.at_any_points_text, + self.evaluate_text + ))) + self.play(Write(self.dot_prod_text)) + self.play( + FadeIn(dot_sym), + ApplyMethod( + self.tangent_sym.next_to, + dot_sym, RIGHT + )) + + self.dot_sym=dot_sym + + + + def get_curve(self,func,on_surface=False ,**kwargs): + config = dict() + config.update(self.default_graph_style) + config.update({ + "t_min": 0, + "t_max": PI/2, + }) + config.update(kwargs) + r=1 + curve=ParametricFunction( + lambda t: self.coords_to_point( + r*np.cos(t), + r*np.sin(t), + ), + **config, + ) + return curve + + + #------------------------------------------------------- + def trasform_to_graphs(self): + on_surface_graph=(self.get_graph( + self.Func,on_surface=True + )) + on_surface_graph.set_style( + stroke_width=5, + stroke_color=YELLOW, + ) + + line_graph=(self.get_graph( + self.Func,on_surface=False + )) + line_graph.set_style( + stroke_width=5, + stroke_color=PINK, + ) + + self.on_surface_graph=on_surface_graph + self.line_graph=line_graph + graph_area=self.get_area(graph=True) + + into_graph=[ + ReplacementTransform( + self.values_on_surface, + on_surface_graph + ), + ReplacementTransform( + self.line_of_int, + line_graph + ), + ReplacementTransform( + self.area, + graph_area + ), + ] + + def get_area(self): + + area =Polygon( + *[ + on_surface.get_point_from_function(t) + for t in np.arange(0,PI,0.01) + ], + *[ + on_base.get_point_from_function(t) + for t in np.arange(PI,0,-0.01) + ], + stroke_width=0, + fill_color=TEAL_A, + fill_opacity=.6, + ) + + return area + + + + + #uploaded by Somnath Pandit.FSF2020_Line_Integrals diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file5_helix.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file5_helix.py new file mode 100644 index 0000000..50aeb33 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file5_helix.py @@ -0,0 +1,245 @@ +from manimlib.imports import * + +class ParametricCurve(ThreeDScene): + + CONFIG = { + "axes_config": { + "x_min": 0, + "x_max": 3, + "y_min": 0, + "y_max": 3, + "z_min": 0, + "z_max": 4, + "a":0 ,"b": 2, "c":0 , "d":2, + "axes_shift":2*IN+1.4*RIGHT+1.4*DOWN, + "x_axis_config": { + "tick_frequency": 1, + "include_tip": False, + }, + "y_axis_config": { + "tick_frequency": 1, + "include_tip": False, + }, + "z_axis_config": { + "tick_frequency": 1, + # "include_tip": False, + }, + }, + + } + + + def construct(self): + + self.setup_axes() + + self.set_camera_orientation( + distance=25, + phi=60 * DEGREES, + theta=40 * DEGREES, + ) + + label=TextMobject("Helix",color=PURPLE).scale(1.6) + label.to_corner(UR,buff=2) + self.add_fixed_in_frame_mobjects(label) + + helix=self.get_helix( + radius=1.5, + t_min= 0, + t_max= 4*PI, + color=PURPLE + ) + parameter_label=TextMobject( + "Parametric equation: ", + color=TEAL + ).next_to(label,DOWN,buff=.3 + ) + parametric_eqn=TextMobject( + "$x=\cos$ (","t", + r")\\$y=\sin $(","t", + r")\\$z$=","t" + ).next_to(parameter_label,DOWN,buff=.1) + parametric_eqn.set_color_by_tex("t",RED) + self.parametric_eqn=parametric_eqn + + parametriztion=VGroup( + parameter_label, + parametric_eqn + ) + + + self.play(ShowCreation(helix),run_time=2) + self.begin_ambient_camera_rotation(.1) + self.wait(1) + self.add_fixed_in_frame_mobjects(parametriztion) + self.play(Write(parametriztion)) + self.wait(1) + self.stop_ambient_camera_rotation() + self.move_camera( + distance=20, + phi=85 * DEGREES, + # theta=-90 * DEGREES, + run_time=3 + ) + scale_axes=VGroup(self.axes,helix).scale(1.2) + self.show_the_parameter() + self.wait(2) + + + + def get_helix(self,radius=1, **kwargs): + config = { + "t_min": 0, + "t_max": 2*PI, + } + config.update(kwargs) + helix= ParametricFunction( + lambda t : self.axes.c2p( + radius*np.cos(t), + radius*np.sin(t), + t/4 + ), + **config + ) + + self.helix=helix + return helix + + def show_the_parameter(self): + t_tracker = ValueTracker(0) + t=t_tracker.get_value + + t_label = TexMobject( + "t = ",color=RED + ).next_to(self.parametric_eqn,DL,buff=.85) + + t_text = always_redraw( + lambda: DecimalNumber( + t(), + color=GOLD, + ).next_to(t_label, RIGHT, MED_SMALL_BUFF) + ) + t_text.suspend_updating() + + dot = Sphere( + radius= 1.5*DEFAULT_DOT_RADIUS, + stroke_width= 1, + fill_opacity= 1.0, + ) + dot.set_color(GOLD) + dot.add_updater(lambda v: v.move_to( + self.helix.get_point_from_function(PI*t()) + )) + + pi = TexMobject( + "\\pi ", + color=GOLD, + ).next_to(t_text,RIGHT,buff=-.3) + + group = VGroup(t_text,t_label,pi).scale(1.5) + + self.wait(1) + self.add_fixed_in_frame_mobjects(group) + t_text.resume_updating() + self.play(FadeIn(group)) + self.add(dot) + self.play( + t_tracker.set_value,2, + rate_func=linear, + run_time=5 + ) + + +#-------------------------------------------------------- + + #customize 3D axes + def get_three_d_axes(self, include_labels=True, include_numbers=False, **kwargs): + config = dict(self.axes_config) + config.update(kwargs) + axes = ThreeDAxes(**config) + axes.set_stroke(width=1.5) + + if include_numbers: + self.add_axes_numbers(axes) + + if include_labels: + self.add_axes_labels(axes) + + # Adjust axis orientation + axes.x_axis.rotate( + 90 * DEGREES, LEFT, + about_point=axes.c2p(0, 0, 0), + ) + axes.y_axis.rotate( + 90 * DEGREES, UP, + about_point=axes.c2p(0, 0, 0), + ) + + + return axes + + + def setup_axes(self): + axes = self.get_three_d_axes(include_labels=True) + axes.scale(1) + # axes.center() + axes.shift(axes.axes_shift) + self.add(axes) + self.axes = axes + + def add_axes_numbers(self, axes): + x_axis = axes.x_axis + y_axis = axes.y_axis + tex_vals_x = [ + ("1", axes.b), + ] + tex_vals_y=[ + ("1", axes.d) + ] + x_labels = VGroup() + y_labels = VGroup() + for tex, val in tex_vals_x: + label = TexMobject(tex) + label.scale(1) + label.next_to(x_axis.n2p(val), DOWN) + label.rotate(180 * DEGREES) + x_labels.add(label) + x_axis.add(x_labels) + x_axis.numbers = x_labels + + for tex, val in tex_vals_y: + label = TexMobject(tex) + label.scale(1) + label.next_to(y_axis.n2p(val), LEFT) + label.rotate(90 * DEGREES) + y_labels.add(label) + + y_axis.add(y_labels) + y_axis.numbers = y_labels + + return axes + + def add_axes_labels(self, axes): + x_label = TexMobject("x") + x_label.next_to(axes.x_axis.get_end(), RIGHT) + axes.x_axis.label = x_label + + y_label = TextMobject("y") + y_label.rotate(90 * DEGREES, OUT) + y_label.next_to(axes.y_axis.get_end(), UP) + axes.y_axis.label = y_label + + z_label = TextMobject("z") + z_label.rotate(90 * DEGREES, LEFT) + z_label.next_to(axes.z_axis.get_zenith(), LEFT) + axes.z_axis.label = z_label + for axis in axes: + axis.add(axis.label) + return axes + + #uploaded by Somnath Pandit.FSF2020_Line_integrals + + + + + diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file4_helix.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file4_helix.gif deleted file mode 100644 index ceedb1f..0000000 Binary files a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file4_helix.gif and /dev/null differ diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file4_vector_line_integral.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file4_vector_line_integral.gif new file mode 100644 index 0000000..8c63d36 Binary files /dev/null and b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file4_vector_line_integral.gif differ diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file5_helix.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file5_helix.gif new file mode 100644 index 0000000..ceedb1f Binary files /dev/null and b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file5_helix.gif differ diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/unfinished_vector_line_integral.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/unfinished_vector_line_integral.py deleted file mode 100644 index d5dda1f..0000000 --- a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/unfinished_vector_line_integral.py +++ /dev/null @@ -1,282 +0,0 @@ -from manimlib.imports import * - -class LineIntegrationProcess(GraphScene): - - CONFIG = { - "x_min" : -0, - "x_max" : 1, - "y_min" : -0, - "y_max" : 1, - "axes_color":WHITE, - "graph_origin": ORIGIN+6.5*LEFT+3*DOWN, - "x_axis_width": 6, - "y_axis_height": 6, - "x_tick_frequency": 1, - "y_tick_frequency": 1, - "default_vector_field_config": { - "delta_x": .5, - "delta_y": .5, - "min_magnitude": 0, - "max_magnitude": 15, - "colors": [BLUE], - "length_func": lambda norm : norm/35, - "opacity": 1.0, - "vector_config": { - "stroke_width":2 - }, - }, - "default_graph_style": { - "stroke_width": 2, - "stroke_color": WHITE, - }, - } - - - def construct(self): - X = RIGHT*self.x_axis_width/(self.x_max- self.x_min) - Y = UP*self.y_axis_height/(self.y_max- self.y_min) - self.X=X ;self.Y=Y - - self.setup_axes(animate=False) - - fn_text=TexMobject( - r"\vec F = x^2\hat i-xy\hat j", - stroke_width=2.5 - ).set_color_by_gradient( - *self.default_vector_field_config["colors"] - ) - fn_text.to_corner(UR,buff=.8).shift(2*LEFT) - - origin=self.graph_origin - v_field=self.get_vector_field( - lambda v: np.array([ - (v[0]-origin[0])**2, - -(v[0]-origin[0])*(v[1]-origin[1]), - 0, - ]), - x_min= -.001+origin[0], - x_max= 5.8+origin[0], - y_min= -0+origin[1], - y_max= 6.+origin[1], - ) - - # self.play(Write(surface)) - # self.play(Write(v_field),Write(fn_text)) - self.add(v_field, fn_text) - self.get_line_of_int() - self.get_dot_product_values() - '''self.get_field_values_on_line() - self.wait(1.5) - - self.remove(surface) - self.trasform_to_graphs()''' - self.wait(2) - - - def get_vector_field(self,func,**kwargs): - config = dict() - config.update(self.default_vector_field_config) - config.update(kwargs) - vector_field= VectorField(func,**config) - self.vector_field=vector_field - - return vector_field - - def get_line_of_int(self): - line_of_int_text=TextMobject(r"Line of integration is\\","$\\vec r(t)=\cos(t)\hat i+\sin(t)\hat j$") - line_of_int_text[1].set_color(PINK) - line_of_int_text.to_edge(TOP,buff=SMALL_BUFF) - - - line_of_int= self.get_graph( - lambda x : np.sqrt(1-x**2), - x_min=1, - x_max=0, - ) - line_of_int.set_style( - stroke_width=3, - stroke_color=PINK, - ) - - # self.play(Write(line_of_int_text)) - self.wait(.5) - # self.play(ShowCreation(line_of_int),run_time=1.5) - self.add(line_of_int) - - self.line_of_int=line_of_int - self.line_of_int_text=line_of_int_text - - def get_dot_product_values(self): - t_tracker = ValueTracker(0) - self.t_tracker = t_tracker - self.get_vector_and_tangent() - self.get_dot_product_graph() - self.wait(1.5) - self.play(ApplyMethod( - self.t_tracker.set_value, PI/2, - rate_func=linear, - run_time=2, - ) - ) - - def get_dot_product_graph(self): - pass - - - def get_vector_and_tangent(self): - self.play(FadeOut(self.axes)) - self.show_vector() - self.show_tangent() - - - def show_vector(self): - t = self.t_tracker.get_value - vect_label=TextMobject( - "$\\vec F(x_i,y_i)$", - color=YELLOW, - stroke_width=2 - ).scale(.8) - - vector = always_redraw( lambda: - self.vector_field.get_vector( - self.coords_to_point( - np.cos(t()), np.sin(t()) - ), - stroke_width=6, - max_stroke_width_to_length_ratio= 8, - ).set_color(YELLOW), - ) - vector.set_color(ORANGE) - vect_label.next_to(vector,RIGHT,buff=.1) - self.add(vector,vect_label) - # self.play(Write(vector),run_time=.2) - - self.vect_label = vect_label - - def show_tangent(self): - tangent_label=TextMobject("$\\vec T(x_i,y_i)$",color="#DC75CD",stroke_width=2).scale(.8) - - t = self.t_tracker.get_value - - tangent = always_redraw(lambda: - Vector( - color="#DC75CD", - stroke_width=6, - ).scale(1).next_to( - self.coords_to_point( - np.cos(t()), np.sin(t()) - ),DR,buff=-.1 - ).rotate( - self.angle_of_tangent( - np.cos(t()), - self.line_of_int, - dx=-0.00001 - ), - about_point=self.coords_to_point( - np.cos(t()), np.sin(t()) - ) - ) - ) - tangent_label.next_to(tangent,UP,buff=.1) - self.play(Write(VGroup(tangent,tangent_label))) - - self.tangent_label=tangent_label - - def dot_product(self): - - dot_sym=Dot().next_to(self.func_val,RIGHT) - - self.play(FadeOut(VGroup( - self.at_any_points_text, - self.evaluate_text - ))) - self.play(Write(self.dot_prod_text)) - self.play( - FadeIn(dot_sym), - ApplyMethod( - self.tangent_sym.next_to, - dot_sym, RIGHT - )) - - self.dot_sym=dot_sym - - - - def get_curve(self,func,on_surface=False ,**kwargs): - config = dict() - config.update(self.default_graph_style) - config.update({ - "t_min": 0, - "t_max": PI/2, - }) - config.update(kwargs) - r=1 - curve=ParametricFunction( - lambda t: self.coords_to_point( - r*np.cos(t), - r*np.sin(t), - ), - **config, - ) - return curve - - - #------------------------------------------------------- - def trasform_to_graphs(self): - on_surface_graph=(self.get_graph( - self.Func,on_surface=True - )) - on_surface_graph.set_style( - stroke_width=5, - stroke_color=YELLOW, - ) - - line_graph=(self.get_graph( - self.Func,on_surface=False - )) - line_graph.set_style( - stroke_width=5, - stroke_color=PINK, - ) - - self.on_surface_graph=on_surface_graph - self.line_graph=line_graph - graph_area=self.get_area(graph=True) - - into_graph=[ - ReplacementTransform( - self.values_on_surface, - on_surface_graph - ), - ReplacementTransform( - self.line_of_int, - line_graph - ), - ReplacementTransform( - self.area, - graph_area - ), - ] - - def get_area(self): - - area =Polygon( - *[ - on_surface.get_point_from_function(t) - for t in np.arange(0,PI,0.01) - ], - *[ - on_base.get_point_from_function(t) - for t in np.arange(PI,0,-0.01) - ], - stroke_width=0, - fill_color=TEAL_A, - fill_opacity=.6, - ) - - return area - - - - - #uploaded by Somnath Pandit.FSF2020_Line_Integrals -- cgit