summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus-of-several-variables/div-curl-grad-and-all-that/Gradient/Gradient_file2_input-output.py
blob: b02e60b9d508911797485e59592ff13cedf6ae15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from manimlib.imports import *
import numpy as np


def function(coordinate):
	x,y = coordinate[:2]
	return np.array([
		0.4*(-x*np.sin((x**2+y**2)))/1*(x**2 + y**2),
		0.4*(-y*np.sin((x**2+y**2)))/1*(x**2 + y**2),
		0,
	])


def function_two(coordinate):
	x,y = coordinate[:2]
	return np.array([
		6*x*y/(x**2+y**2+1)**2,
		-3*(x**2 -y**2 +1)/(x**2+y**2+1)**2,
		0,
	])

def function_three(coordinate):
	x,y = coordinate[:2]
	return np.array([
		np.exp(x)*np.cos(y),
		-np.exp(x)*np.sin(y),
		0,
	])


class Second(ThreeDScene):
	def construct(self):
		axes = ThreeDAxes()
		self.add(axes)
		self.set_camera_orientation(phi=45*DEGREES,theta=60*DEGREES,distance=40)
		self.begin_ambient_camera_rotation(rate=0.05)

		surface = ParametricSurface(
			lambda u, v: np.array([
				0.4*u,
				0.4*v,
				0.4*np.cos(np.sqrt((u**2)+(v**2)))
			]),u_min=-10,u_max=10, v_min=-10,v_max=10, checkerboard_colors = (["#1C6E8C", "#1C6E8C"]), stroke_color = "#1C6E8C").fade(0.7)

		text_func = TexMobject(r"\textbf{Input: Function}").shift(4.4*LEFT+3.3*UP).scale(0.7).set_stroke(width = 1.2)
		text_field = TexMobject(r"\textbf{Output: Vector Field}").shift(4.4*LEFT+3.3*UP).scale(0.7).set_stroke(width = 1.2)
		field = VectorField(function, x_min = -4, x_max = 4, y_min = -4, y_max = 4, colors = (["#CC2936", "#4D8B31","#FFAD05"]))
		
		
		self.add_fixed_in_frame_mobjects(text_func)
		self.play(ShowCreation(surface))
		self.wait(3)
		self.stop_ambient_camera_rotation()
		self.move_camera(phi=0*DEGREES, theta=0*DEGREES)

		self.play(FadeIn(field),FadeOut(text_func))
		self.add_fixed_in_frame_mobjects(text_field)
		self.wait()
		self.play(FadeOut(surface), FadeOut(axes))
		self.wait()


class Third(ThreeDScene):
	def construct(self):
		axes = ThreeDAxes()
		self.add(axes)
		self.set_camera_orientation(phi=45*DEGREES,theta=60*DEGREES,distance=40)
		self.begin_ambient_camera_rotation(rate=0.2)




		surface_two = ParametricSurface(
			lambda x, y: np.array([
			x,
			y,
			-3*y/(x**2+y**2+1)
		]),u_min=-2,u_max=2, v_min=-2,v_max=2).set_color(BLUE_E).fade(0.7).scale(1.7)

		text_func = TexMobject(r"f = \frac{-3y}{x^{2} + y^{2} +1}").shift(4.8*LEFT+3*UP).scale(0.7)
		text_field = TexMobject(r"\nabla", r"f = \begin{bmatrix}\frac{\partial f}{\partial x}\\\frac{\partial f}{\partial y}\end{bmatrix}").shift(4.8*LEFT+3*UP).scale(0.7)
		text_field_a = TexMobject(r"\nabla", r" f = \begin{bmatrix} \frac{6xy}{(x^{2} + y^{2} + 1)^{2}}\\-3\frac{x^{2} - y^{2} + 1}{(x^{2} + y^{2} + 1)^{2}}\end{bmatrix}").shift(4.8*LEFT+3*UP).scale(0.7)

		field_two = VectorField(function_two, x_min = -3, x_max = 3, y_min = -3, y_max = 3, colors = (["#CC2936", "#4D8B31","#FFAD05"]))
		text_field[0].set_color("#CC2936")
		text_field_a[0].set_color("#CC2936")



		self.add_fixed_in_frame_mobjects(text_func)
		self.play(ShowCreation(surface_two))
		self.wait(3)
		self.stop_ambient_camera_rotation()
		self.move_camera(phi=0*DEGREES, theta=0*DEGREES)

		self.play(FadeIn(field_two),FadeOut(text_func))
		self.add_fixed_in_frame_mobjects(text_field)
		self.wait()
		self.play(FadeOut(surface_two))
		self.wait()



class Fourth(ThreeDScene):
	def construct(self):
		axes = ThreeDAxes()
		self.add(axes)
		self.set_camera_orientation(phi=45*DEGREES,theta=60*DEGREES,distance=100)
		self.begin_ambient_camera_rotation(rate=0.2)

		surface = ParametricSurface(
			lambda u, v: np.array([
				u,
				v,
				np.exp(u)*np.cos(v)
			]),u_min=-3,u_max=3, v_min=-3,v_max=3).set_color(BLUE_E).fade(0.7)

		text_func = TexMobject(r"\textbf{Input: Function}").shift(4.4*LEFT+3.3*UP).scale(0.7)
		text_field = TexMobject(r"\textbf{Output: Vector Field}").shift(4.4*LEFT+3.3*UP).scale(0.7)
		field = VectorField(function_three, x_min = -3, x_max = 3, y_min = -3, y_max = 3)
		
		
		self.add_fixed_in_frame_mobjects(text_func)
		self.play(ShowCreation(surface))
		self.wait(3)

		self.stop_ambient_camera_rotation()
		self.move_camera(phi=0*DEGREES, theta=0*DEGREES)

		self.play(FadeIn(field),FadeOut(text_func))
		self.add_fixed_in_frame_mobjects(text_field)
		self.wait()
		self.add_fixed_in_frame_mobjects(text_field_a)
		self.play(ReplacementTransform(text_field, text_field_a))
		self.play(FadeOut(surface))
		self.wait()