diff options
Diffstat (limited to 'FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals')
11 files changed, 1614 insertions, 0 deletions
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 new file mode 100644 index 0000000..7e4299d --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/README.md @@ -0,0 +1,15 @@ +**file1_scalar_line_int_as_sum** +![file1_scalar_line_int_as_sum](gifs/file1_scalar_line_int_as_sum.gif) + +**file2_scalar_line_integral** +![file2_scalar_line_integral](gifs/file2_scalar_line_integral.gif) + + +**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.gif) + +**file5_helix** +![file5_helix](gifs/file5_helix.gif) diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file1_scalar_line_int_as_sum.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file1_scalar_line_int_as_sum.py new file mode 100644 index 0000000..af32ebf --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file1_scalar_line_int_as_sum.py @@ -0,0 +1,227 @@ +from manimlib.imports import * + + +class LineIntegrationAsSum(GraphScene): + CONFIG = { + "x_min" : 0, + "x_max" : 10, + "y_min" : 0, + "y_max" : 6, + "graph_origin": ORIGIN+5*LEFT+3*DOWN, + "x_axis_width": 10, + "y_axis_height": 6 , + "x_tick_frequency": 2, + "y_tick_frequency": 2, + "Func":lambda x : 1+x**1.3*np.exp(-.12*(x-2)**2)*np.sin(x/4), + "a": 1 ,"b": 9, "n": 15, + } + + 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) + + curve=self.get_graph( + self.Func, + x_min=self.a, + x_max=self.b, + ) + curve.set_color([BLACK,BLUE,BLUE,BLUE,BLACK]) + curve_label= self.get_graph_label( + curve, + label="\\text{path of intgration}", + x_val=4, + direction=UR, + buff=.6, + color=BLUE + ) + self.curve=curve + self.curve_label=curve_label + + self.play(ShowCreation(VGroup(curve,curve_label))) + self.wait(.6) + self.break_in_arcs() + self.show_the_sum() + self.construct_equation() + self.wait(2) + + + + def break_in_arcs(self): + + self.write_about_breaking() + + dl=0.8 + self.get_breakers(dl) + self.wait(2) + self.play(FadeOut(self.upto_break_text)) + self.dl=dl + + def write_about_breaking(self): + breaking_text=TextMobject("\\texttt{..broken}"," into small", "subarcs") + breaking_text.set_color_by_tex_to_color_map({ + "broken":RED,"subarcs": BLUE + }) + breaking_text.next_to(self.curve_label,DOWN) + breaking_text.align_to(self.curve_label,LEFT) + self.play( + Write(breaking_text) + ) + + self.upto_break_text=VGroup( + self.curve_label, + breaking_text, + ) + + def get_breakers(self,dl): + point=self.a + points=[] + while point<(self.b-dl) : + start=point + end=point+dl + points += [end] + breaker=Line( + self.input_to_graph_point(start,self.curve), + self.input_to_graph_point(end,self.curve), + stroke_width=2, + color=RED, + ) + breaker.rotate(PI/2).scale(.5) + + point=end + self.play(FadeIn(breaker),run_time=.2) + # self.add(breaker) + + del points[-1] + self.points=points + + + def show_the_sum(self): + at_any_points_text=TextMobject("At any ","point", "in each ", "subarc") + at_any_points_text.set_color_by_tex_to_color_map({ + "point":YELLOW , "subarc": BLUE + }) + at_any_points_text.to_edge(TOP,buff=SMALL_BUFF) + + evaluate_text=TextMobject("$f(x,y)$ ", "is evaluated").next_to(at_any_points_text,DOWN) + evaluate_text.set_color_by_tex("$f(x,y)$",ORANGE) + + self.at_any_points_text=at_any_points_text + self.evaluate_text=evaluate_text + + + dots=[] + for point in self.points: + + dot=Dot( + point=self.input_to_graph_point(point,self.curve), + radius= .7*DEFAULT_DOT_RADIUS, + stroke_width= 0, + fill_opacity= 1.0, + color= YELLOW, + ) + dots+=[dot] + + self.play( + Write(at_any_points_text), + FadeIn(VGroup(*dots)),run_time=1.5 + ) + self.wait() + self.position_of_point_irrelevent() + self.multiply_with_function(dots) + + + + def multiply_with_function(self,dots): + index=-(len(self.points)//3) + dot=dots[index] + + + multiply_text=TexMobject("f(x_i,y_i)", "\\text{ is multiplied with }","\\Delta s_i") + multiply_text.set_color_by_tex_to_color_map({ + "f(x_i,y_i)":ORANGE , "\\Delta s_i": BLUE + }) + multiply_text.to_edge(TOP,buff=MED_SMALL_BUFF) + + point_coord=TextMobject("$(x_i,y_i)$",color=YELLOW) + point_coord.next_to(dot,DL,buff=.01).scale(.8) + + func_val=TextMobject("$f(x_i,y_i)$",color=ORANGE) + func_val.next_to(dot,UR) + + sum_up_text=TextMobject("and "," summed ", "for all i' s") + sum_up_text.set_color_by_tex("summed",PURPLE) + sum_up_text.next_to(multiply_text,DOWN) + + + self.play(FadeIn(VGroup( + point_coord,dot + ))) + self.play(Write(self.evaluate_text)) + self.play(Write(func_val)) + + self.wait(2) + self.remove(point_coord) + self.get_ds(dots,index) + self.play(GrowFromCenter(self.ds_brace_group)) + self.wait(2) + self.play(FadeOut(VGroup( + self.ds_brace, + self.at_any_points_text, + self.evaluate_text + ))) + self.play(Write(multiply_text)) + self.play(ApplyMethod( + self.ds_brace_label.next_to, + func_val, RIGHT,buff=.2 + )) + self.play(Write(sum_up_text)) + dot.set_color(ORANGE).scale(1.2) + self.play(FadeIn(VGroup(*[ + dot.set_color(ORANGE).scale(1.4) + for dot in dots ] + ))) + self.func_val=func_val + self.sum_text_group=VGroup(multiply_text,sum_up_text) + + def position_of_point_irrelevent(self): + pass + + + + def get_ds(self,dots,index): + p1= dots[index] + p2= dots[index+1] + ds_brace=Brace(VGroup(p1,p2),DL) + ds_brace.move_to(p1,UR) + ds_brace_label=ds_brace.get_text("$\Delta s_i$", buff = .05) + ds_brace_label.set_color(BLUE) + self.ds_brace=ds_brace + self.ds_brace_label=ds_brace_label + self.ds_brace_group=VGroup(ds_brace,ds_brace_label) + + + def construct_equation(self): + sum_eqn=TextMobject("$$\\sum_i^{ } $$").set_color(PURPLE) + sum_eqn.move_to(self.graph_origin+7*self.X+4*self.Y) + + line_integral_text=TextMobject("The Value of the line integral is").next_to(self.sum_text_group,IN) + approx=TextMobject("$\\approx$",color=RED).next_to(sum_eqn,LEFT) + multipled=VGroup(self.func_val,self.ds_brace_label) + self.play(FadeIn(sum_eqn)) + self.play(ApplyMethod( + multipled.next_to,sum_eqn,RIGHT + )) + self.wait() + self.play(FadeOut(self.sum_text_group)) + self.play(Write(line_integral_text)) + self.play(FadeIn(approx)) + + + +#uploaded by Somnath Pandit.FSF2020_Line Integrals + + + diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.py new file mode 100644 index 0000000..200f768 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.py @@ -0,0 +1,427 @@ +from manimlib.imports import * + +class LineIntegrationProcess(SpecialThreeDScene): + + CONFIG = { + "axes_config": { + "x_min": -4, + "x_max": 4, + "y_min": 0, + "y_max": 4, + "z_min": 0, + "z_max": 4, + "a":-3 ,"b": 3, "c":0 , "d":3.5, + "axes_shift":3*IN, + "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, + }, + "num_axis_pieces": 1, + }, + "default_graph_style": { + "stroke_width": 2, + "stroke_color": WHITE, + }, + "default_surface_config": { + "fill_opacity": 0.5, + "checkerboard_colors": [LIGHT_GREY], + "stroke_width": 0.2, + "stroke_color": WHITE, + "stroke_opacity": 0.75, + }, + "Func": lambda x,y: 1+x**2*y/15 + } + + + def construct(self): + + self.setup_axes() + axes=self.axes + + self.set_camera_orientation(distance=35, + phi=60 * DEGREES, + theta=-60 * DEGREES, + ) + + fn_text=TextMobject("$z=2+x^2y$").set_color(BLUE) + fn_text.to_corner(UR,buff=.8).shift(DOWN) + + #get the surface + surface= self.get_surface( + lambda x , y: + self.Func(x,y) + ) + surface.set_style( + fill_opacity=0.5, + fill_color=BLUE_D, + stroke_width=0.5, + stroke_color=WHITE, + ) + + + # self.play(Write(surface)) + self.add_fixed_in_frame_mobjects(fn_text) + self.play(Write(surface),Write(fn_text)) + self.get_line_of_int() + self.begin_ambient_camera_rotation(rate=-0.035) + self.get_field_values_on_line() + self.wait(1.5) + self.area=self.get_area() + area_text=TextMobject("Line"," Integral in the",r" scalar field\\"," means this" ,"area") + area_text.set_color_by_tex_to_color_map({ + "Line": PINK, "scalar":BLUE, "area":TEAL_A + }) + area_text.to_edge(TOP,buff=MED_SMALL_BUFF) + + self.remove(self.values_on_line_text) + self.add_fixed_in_frame_mobjects(area_text) + self.play(Write(area_text)) + self.play(Write(self.area),run_time=2) + self.play(FadeOut(VGroup(surface,fn_text))) + self.move_camera( + # distance=20, + phi=90 * DEGREES, + # theta=-90 * DEGREES, + # added_anims=into_graph, + run_time=2 + ) + self.wait(2) + + self.stop_ambient_camera_rotation() + # self.get_lines() + + self.remove(axes,surface) + self.trasform_to_graphs() + self.wait(2) + + + + + def get_line_of_int(self): + line_of_int_text=TextMobject(r"Line of integration is\\","$\\vec r(t)=\cos(t)\hat x+\sin(t)\hat y$") + line_of_int_text[1].set_color(PINK) + line_of_int_text.to_edge(TOP,buff=SMALL_BUFF) + + + line_of_int=(self.get_curve( + self.Func,on_surface=False + )) + line_of_int.set_style( + stroke_width=5, + stroke_color=PINK, + ) + + self.add_fixed_in_frame_mobjects(line_of_int_text) + self.play(Write(line_of_int_text)) + self.wait() + self.play(ShowCreation(line_of_int),run_time=3) + # self.add(line_of_int) + + self.line_of_int=line_of_int + self.line_of_int_text=line_of_int_text + + def get_field_values_on_line(self): + self.remove(self.line_of_int_text) + + values_on_line_text=TextMobject("Values"," of"," function","on the ","line") + values_on_line_text.set_color_by_tex_to_color_map({ + "Values":YELLOW, "function":BLUE,"line":PINK + }) + values_on_line_text.to_edge(TOP,buff=SMALL_BUFF) + + values_on_surface=(self.get_curve( + self.Func,on_surface=True + )) + values_on_surface.set_style( + stroke_width=5, + stroke_color=YELLOW, + ) + + self.add_fixed_in_frame_mobjects(values_on_line_text) + self.play(Write(values_on_line_text)) + # self.wait() + self.play(ShowCreation(values_on_surface),run_time=3) + # self.add(values_on_surface) + + self.values_on_surface=values_on_surface + self.values_on_line_text=values_on_line_text + + + 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 + ), + ] + + self.move_camera( + # distance=20, + phi=90 * DEGREES, + theta=-90 * DEGREES, + added_anims=into_graph, + run_time=2 + ) + + def get_area(self,graph=False): + axes=self.axes + if graph: + on_surface=self.on_surface_graph + on_base=self.line_graph + else: + on_surface=self.values_on_surface + on_base=self.line_of_int + 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 + + 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, + }) + config.update(kwargs) + r=abs(self.axes.a) + curve=ParametricFunction( + lambda t: self.axes.c2p( + r*np.cos(t), + r*np.sin(t), + func(r*np.cos(t), r*np.sin(t))*bool(on_surface) + ), + **config, + ) + return curve + + + def get_surface(self, func, **kwargs): + axes=self.axes + config = { + "u_min": axes.a-.2, + "u_max": axes.b+.2, + "v_min": axes.c-.1, + "v_max": axes.d, + "resolution": ( + 2*(axes.y_max - axes.y_min) // axes.y_axis.tick_frequency, + (axes.x_max - axes.x_min) // axes.x_axis.tick_frequency, + ), + } + + config.update(self.default_surface_config) + config.update(kwargs) + return ParametricSurface( + lambda x,y : axes.c2p( + x, y, func(x, y) + ), + **config + ) + + def get_graph(self,func,on_surface=False ,**kwargs): + config = dict() + config.update(self.default_graph_style) + config.update({ + "t_min": 0, + "t_max": PI, + }) + config.update(kwargs) + slice_curve=ParametricFunction( + lambda t: self.axes.c2p( + 4*np.cos(t), + 0, + 2+func(3*np.cos(t), 3*np.sin(t))*bool(on_surface) + ), + **config, + ) + return slice_curve + + def get_lines(self): + pass + axes = self.axes + labels=[axes.x_axis.n2p(axes.a), axes.x_axis.n2p(axes.b), axes.y_axis.n2p(axes.c), + axes.y_axis.n2p(axes.d)] + + + surface_corners=[] + for x,y,z in self.region_corners: + surface_corners.append([x,y,self.Func(x,y)]) + + lines=VGroup() + for start , end in zip(surface_corners, + self.region_corners): + lines.add(self.draw_lines(start,end,"PINK")) + + for start , end in zip(labels, + self.region_corners): + # lines.add(self.draw_lines(start,end,"BLUE")) + # print (start,end) + pass + # self.play(ShowCreation(lines)) + self.add(lines) + + + def draw_lines(self,start,end,color): + start=self.axes.c2p(*start) + end=self.axes.c2p(*end) + line=DashedLine(start,end,color=color) + + return line + +#------------------------------------------------------- + #customize 3D axes + def get_three_d_axes(self, include_labels=True, include_numbers=True, **kwargs): + config = dict(self.axes_config) + config.update(kwargs) + axes = ThreeDAxes(**config) + axes.set_stroke(width=2) + self.axes=axes + + 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), + ) + + # Add xy-plane + input_plane = self.get_surface( + lambda x, t: 0 + ) + '''input_plane.set_style( + fill_opacity=0.3, + fill_color=PINK, + stroke_width=.2, + stroke_color=WHITE, + )''' + + axes.input_plane = input_plane + + self.region_corners=[ + input_plane.get_corner(pos) for pos in (DL,DR,UR,UL)] + + return axes + + + def setup_axes(self): + axes = self.get_three_d_axes(include_labels=True) + axes.add(axes.input_plane) + 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), + ("-1", axes.a), + ] + 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, RIGHT) + 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/file3_vector_line_int_as_sum.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file3_vector_line_int_as_sum.py new file mode 100644 index 0000000..78294cc --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file3_vector_line_int_as_sum.py @@ -0,0 +1,326 @@ +from manimlib.imports import * + + +class LineIntegrationAsSum(GraphScene): + CONFIG = { + "x_min" : 0, + "x_max" : 10, + "y_min" : 0, + "y_max" : 6, + "graph_origin": ORIGIN+5*LEFT+3*DOWN, + "x_axis_width": 10, + "y_axis_height": 6 , + "x_tick_frequency": 2, + "y_tick_frequency": 2, + "Func":lambda x : 1+x**1.3*np.exp(-.12*(x-2)**2)*np.sin(x/4), + "a": 1 ,"b": 9, "n": 15, + } + + 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) + + + curve=self.get_graph( + self.Func, + x_min=self.a, + x_max=self.b, + ) + curve.set_color([BLACK,BLUE,BLUE,BLUE,BLACK]) + curve_label= self.get_graph_label( + curve, + label="\\text{path of intgration}", + x_val=4, + direction=UR, + buff=.6, + color=BLUE + ) + self.curve=curve + self.curve_label=curve_label + + self.get_vector_field() + + + self.play(ShowCreation(VGroup(curve,curve_label))) + self.wait(.6) + self.break_in_arcs() + self.show_the_sum() + + self.wait(2) + + + def get_vector_field(self): + func = lambda v: np.array([ + v[0], # x + -v[1], # y + 0 # z + ]) + vector_field= VectorField( + func, + delta_x=1, + delta_y=1, + colors=[GREEN_A,GREEN_C], + length_func= lambda norm: .8*sigmoid(norm), + vector_config={ + "stroke_width": 2 + } + ) + + self.vector_field= vector_field + + + def break_in_arcs(self): + + self.write_about_breaking() + + dl=0.8 + self.get_breakers(dl) + self.wait(2) + self.play(FadeOut(self.upto_break_text)) + self.dl=dl + + def write_about_breaking(self): + breaking_text=TextMobject("\\texttt{..broken}"," into small", "subarcs") + breaking_text.set_color_by_tex_to_color_map({ + "broken":RED,"subarcs": BLUE + }) + breaking_text.next_to(self.curve_label,DOWN) + breaking_text.align_to(self.curve_label,LEFT) + self.play( + Write(breaking_text) + ) + + self.upto_break_text=VGroup( + self.curve_label, + breaking_text, + ) + + def get_breakers(self,dl): + point=self.a + points=[] + while point<(self.b-dl) : + start=point + end=point+dl + points += [end] + breaker=Line( + self.input_to_graph_point(start,self.curve), + self.input_to_graph_point(end,self.curve), + stroke_width=2, + color=RED, + ) + breaker.rotate(PI/2).scale(.5) + + point=end + self.play(FadeIn(breaker),run_time=.2) + # self.add(breaker) + + del points[-1] + self.points=points + + + def show_the_sum(self): + at_any_points_text=TextMobject("At any ","point", "in each ", "subarc") + at_any_points_text.set_color_by_tex_to_color_map({ + "point":YELLOW , "subarc": BLUE + }) + at_any_points_text.to_edge(TOP,buff=SMALL_BUFF) + + evaluate_text=TextMobject("$\\vec F(x,y)$ ", "is evaluated").next_to(at_any_points_text,DOWN) + evaluate_text.set_color_by_tex("$\\vec F(x,y)$",ORANGE) + + multiply_text=TextMobject("...is multiplied with ","$\\Delta s_i$") + multiply_text.set_color_by_tex("\\Delta s_i", BLUE) + multiply_text.next_to(at_any_points_text,DOWN) + + + + self.at_any_points_text=at_any_points_text + self.evaluate_text=evaluate_text + self.multiply_text=multiply_text + + dots=[] + for point in self.points: + + dot=Dot( + point=self.input_to_graph_point(point,self.curve), + radius= .7*DEFAULT_DOT_RADIUS, + stroke_width= 0, + fill_opacity= 1.0, + color= YELLOW, + ) + dots+=[dot] + + self.play( + Write(at_any_points_text), + FadeIn(VGroup(*dots)),run_time=1.5 + ) + self.dots=dots + + self.wait() + self.show_the_dot_product() + self.multiply_with_ds() + self.construct_equation() + + + def show_the_dot_product(self): + index=-(len(self.points)//3) + self.index=index + + dot=self.dots[index] + + + dot_prod_text=TextMobject("Dot Product of", "$\\vec F(x_i,y_i)$", "and","$\\vec T(x_i,y_i)$") + dot_prod_text.set_color_by_tex_to_color_map({ + "\\vec F(x_i,y_i)":ORANGE , + "\\vec T(x_i,y_i)": "#DC75CD" , + }) + dot_prod_text.to_edge(TOP,buff=SMALL_BUFF) + + + point_coord=TextMobject("$(x_i,y_i)$",color=YELLOW) + point_coord.next_to(dot,DL,buff=.01).scale(.8) + + func_val=TextMobject("$\\vec F(x_i,y_i)$",color=ORANGE) + func_val.next_to(dot,UR).scale(.8) + + self.dot_prod_text=dot_prod_text + self.func_val=func_val + + dot.set_color(ORANGE).scale(1.2) + + + self.play(FadeIn(VGroup(point_coord,dot))) + self.play(Write(self.evaluate_text)) + self.wait(1) + self.play(FadeOut(self.vector_field)) + self.get_vector_and_tangent() + self.dot_product() + + + self.wait(2) + self.remove(point_coord) + + + def get_vector_and_tangent(self): + dot=self.dots[self.index] + self.show_specific_vectors(dot) + self.play(Write(self.func_val)) + self.wait(1) + self.show_tangent(dot) + self.play(FadeIn(VGroup(*[ + dot.set_color(ORANGE).scale(1.4) + for dot in self.dots ] + ))) + + + def show_specific_vectors(self,dots): + for dot in dots: + vector=self.vector_field.get_vector(dot.get_center()) + vector.set_color(ORANGE) + + self.play(Write(vector),run_time=.2) + + + def show_tangent(self,dot): + tangent_sym=TextMobject("$\\vec T(x_i,y_i)$",color="#DC75CD").scale(.8) + x=dot.get_center() + angle=self.angle_of_tangent( + self.point_to_coords(x)[0], + self.curve, + dx=0.01 + ) + vect = Vector().rotate(angle,about_point=x) + vect.set_color("#DC75CD") + tangent=vect.next_to(x,DR,buff=0) + tangent_sym.next_to(tangent,DOWN,buff=.1) + self.play(Write(VGroup(tangent,tangent_sym))) + + self.tangent_sym=tangent_sym + + 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 multiply_with_ds(self): + self.get_ds() + + self.play(GrowFromCenter(self.ds_brace_group)) + self.wait(2) + self.play(Write(self.multiply_text)) + self.play(ApplyMethod( + self.ds_brace_label.next_to, + self.tangent_sym, RIGHT,buff=.15 + )) + + + + def get_ds(self): + p1= self.dots[self.index] + p2= self.dots[self.index+1] + ds_brace=Brace(VGroup(p1,p2),DL) + ds_brace.move_to(p1,UR) + ds_brace_label=ds_brace.get_text("$\Delta s_i$", buff = .05) + ds_brace_label.set_color(BLUE) + self.ds_brace=ds_brace + self.ds_brace_label=ds_brace_label + self.ds_brace_group=VGroup(ds_brace,ds_brace_label) + + + def construct_equation(self): + sum_up_text=TextMobject("and"," summed ", "for all i' s") + sum_up_text.set_color_by_tex("summed",PURPLE_A) + sum_up_text.next_to(self.multiply_text,DOWN,buff=MED_SMALL_BUFF) + sum_up_text.shift(LEFT) + + sum_eqn=TextMobject("$$\\sum_i^{ } $$").set_color(PURPLE_A) + sum_eqn.move_to(self.graph_origin+6.5*self.X+4*self.Y) + + line_integral_text=TextMobject("The Value of the"," line ","integral is").to_edge(TOP,buff=MED_SMALL_BUFF) + line_integral_text.set_color_by_tex("line",BLUE_C) + approx=TextMobject("$\\approx$",color=RED).next_to(sum_eqn,LEFT) + multipled=VGroup( + self.func_val, + self.dot_sym, + self.tangent_sym, + self.ds_brace_label + ) + + + self.play(Write(sum_up_text)) + self.show_specific_vectors(self.dots) + self.play(FadeIn(sum_eqn)) + self.play(ApplyMethod( + multipled.next_to,sum_eqn,RIGHT + )) + self.wait() + self.play(FadeOut(VGroup( + self.dot_prod_text, + self.multiply_text, + sum_up_text + ))) + self.play(Write(line_integral_text)) + self.play(FadeIn(approx)) + + + +#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..6730820 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file4_vector_line_integral.py @@ -0,0 +1,374 @@ +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.3*LEFT+3*DOWN, + "x_axis_width": 5.5, + "y_axis_height": 5.5, + "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_edge(TOP,buff=.1).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.4+origin[0], + y_min= -0+origin[1], + y_max= 5.5+origin[1], + ) + + self.add(v_field, fn_text) + self.play(Write(fn_text)) + self.wait(2) + self.get_line_of_int() + self.get_dot_product_values() + self.wait(2) + self.remove(v_field,fn_text) + self.write_area_as_intgral_value() + 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_corner(UR,buff=.8) + + + 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=2) + # 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/6, + rate_func=linear, + run_time=2.5, + ) + ) + self.wait(1) + self.play(ApplyMethod( + self.t_tracker.set_value, PI/2, + rate_func=linear, + run_time=4, + ) + ) + self.dot_prod_graph.suspend_updating() + + def get_vector_and_tangent(self): + vect_tangent_text=TextMobject( + "Get the"," vector",r" and\\"," tangent", + " on the"," line" + ) + vect_tangent_text.set_color_by_tex_to_color_map({ + "tangent": ORANGE, "vector": YELLOW, "line":PINK + }) + vect_tangent_text.to_corner(UR,buff=.8) + self.vect_tangent_text= vect_tangent_text + + self.play(FadeOut(self.axes)) + self.remove(self.line_of_int_text) + self.play(Write(vect_tangent_text)) + self.show_vector() + self.show_tangent() + self.wait(1.3) + + 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), + ) + + vect_label.next_to(vector,RIGHT,buff=.1) + vector_group= VGroup(vector,vect_label) + + # self.add(vector_group) + self.play(Write(vector_group),run_time=1) + self.wait(.4) + + self.vect_label = vect_label + self.vector_group= vector_group + + def show_tangent(self): + tangent_label=TextMobject( + "$\\vec T(x_i,y_i)$", + color=ORANGE, + stroke_width=2 + ).scale(.8) + + t = self.t_tracker.get_value + + tangent = always_redraw(lambda: + Vector( + color=ORANGE, + 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) + tangent_group=VGroup(tangent,tangent_label) + + # self.add(tangent_group) + self.play(Write(tangent_group)) + self.wait(.6) + + self.tangent_label=tangent_label + self.tangent_group=tangent_group + + def get_dot_product_graph(self): + t = self.t_tracker.get_value + + self.start_x= 1.3 ; self.end_x=2.3 + + t_axis= self.get_graph( + lambda x : 2.0/5, + x_min= self.start_x, + x_max= self.end_x, + ).set_style( + stroke_width=4, + ) + + dot_prod_axis= Vector(3*UP).next_to( + t_axis,LEFT,buff=-.1 + ).set_color(GREEN) + dot_prod_label=TexMobject( + "\\vec F","\\cdot","\\vec T", + stroke_width= 1.5, + ).next_to(dot_prod_axis,UP).scale(.8) + dot_prod_label[0].set_color(YELLOW) + dot_prod_label[2].set_color(ORANGE) + + dot_prod_graph_axes= VGroup(t_axis,dot_prod_axis) + + self.write_about_graph() + self.wait(1) + # self.add(dot_prod_graph_axes) + self.play(Write(dot_prod_graph_axes)) + self.show_the_parameter(t,t_axis) + self.wait(.6) + self.play(ReplacementTransform( + self.vect_label,dot_prod_label[0] + )) + self.play(ReplacementTransform( + self.tangent_label,dot_prod_label[1:3] + )) + self.show_graph_area(t_axis) + + self.dot_prod_graph_axes= dot_prod_graph_axes + self.dot_prod_label= dot_prod_label + + def write_about_graph(self): + graph_text=TextMobject( + "Graph",r" of the "," vector",r" $-$\\ ", + r"tangent",r" dot product\\", + " with the parameter ","$t$" + ) + graph_text.set_color_by_tex_to_color_map({ + "Graph":GREEN, "vector": YELLOW, + "tangent":ORANGE, "$t$":RED + }) + graph_text.to_corner(UR,buff=.5) + self.graph_text=graph_text + + self.remove(self.vect_tangent_text) + self.play(Write(graph_text),run_time=4) + + def show_the_parameter(self,t,t_axis): + t_dot=Dot(color=RED).next_to(t_axis,LEFT,buff=0) + t_dot.add_updater(lambda obj : + obj.move_to(self.c2g([t(),0]) + )) + t_text=TextMobject("$t$=").next_to(t_dot,UP,buff=.25) + t_val=always_redraw( + lambda: DecimalNumber( + t()/PI, + color=GOLD + ).next_to(t_text,RIGHT,buff=0).scale(.8) + ) + t_label=VGroup( + t_text,t_val + ).set_color(RED) + + + pi = TexMobject( + "\\pi ", + color=GOLD, + ).next_to(t_val,RIGHT,buff=0.05) + t_label.add(pi) + + t_label.add_updater(lambda label : + label.next_to(t_dot,UP) + ) + + t_group=VGroup(t_dot,t_label) + + # self.add(t_group) + self.play(Write(t_group)) + + self.t_group= t_group + + + def show_graph_area(self,t_axis): + t = self.t_tracker.get_value + dot_prod_graph= always_redraw(lambda: Polygon( + *[ + self.c2g([t,-2*np.cos(t)**2*np.sin(t)]) + for t in np.arange(0,t(),0.01) + ], + *[ + self.c2g([t,0]) + for t in [ t(),0 ] + ], + stroke_width=2.5, + fill_color=TEAL_D, + fill_opacity=.6, + )) + + self.add(dot_prod_graph) + + self.dot_prod_graph=dot_prod_graph + + def c2g(self,coord): + """ get points for the dot product graph + from its coordinates""" + + return self.coords_to_point( + self.start_x+coord[0]/(PI/2), + 2.0/5+coord[1]/2, + ) + + + def write_area_as_intgral_value(self): + area_text=TextMobject( + "Value of the "," line"," integral in the", + r"Vector field\\", + "is equal to this ","area" + ) + area_text.set_color_by_tex_to_color_map({ + "Vector field": BLUE, "line":PINK, "area":TEAL_C + }) + area_text.to_edge(TOP,buff=MED_SMALL_BUFF) + + + self.play(FadeOut(VGroup( + self.line_of_int, + self.vector_group, + self.tangent_group, + self.t_group, + self.dot_prod_graph_axes, + self.dot_prod_label, + self.graph_text + ) + )) + area= self.dot_prod_graph.copy().scale(1.3) + area.next_to(area_text,DOWN,buff=1.5) + + # self.add(area_text) + self.play(Write(area_text),run_time=4) + self.play(ReplacementTransform( + self.dot_prod_graph, + area + )) + self.wait(.5) + + #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/file1_scalar_line_int_as_sum.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file1_scalar_line_int_as_sum.gif Binary files differnew file mode 100644 index 0000000..17ea3f0 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file1_scalar_line_int_as_sum.gif diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file2_scalar_line_integral.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file2_scalar_line_integral.gif Binary files differnew file mode 100644 index 0000000..f9a8f98 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file2_scalar_line_integral.gif diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file3_vector_line_int_as_sum.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file3_vector_line_int_as_sum.gif Binary files differnew file mode 100644 index 0000000..46b35bc --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file3_vector_line_int_as_sum.gif 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 Binary files differnew file mode 100644 index 0000000..1be7e1e --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file4_vector_line_integral.gif 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 Binary files differnew file mode 100644 index 0000000..ceedb1f --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/gifs/file5_helix.gif |