-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathte.py
135 lines (117 loc) · 4.13 KB
/
te.py
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
from manim_imports_ext import *
class TrigRepresentationsScene(Scene):
CONFIG = {
"unit_length" : 1.5,
"arc_radius" : 0.5,
"axes_color" : WHITE,
"circle_color" : RED,
"theta_color" : YELLOW,
"theta_height" : 0.3,
"theta_value" : np.pi/5,
"x_line_colors" : MAROON_B,
"y_line_colors" : BLUE,
}
def setup(self):
self.init_axes()
self.init_circle()
self.init_theta_group()
def init_axes(self):
self.axes = Axes(
unit_size = self.unit_length,
)
self.axes.set_color(self.axes_color)
self.add(self.axes)
def init_circle(self):
self.circle = Circle(
radius = self.unit_length,
color = self.circle_color
)
self.add(self.circle)
def init_theta_group(self):
self.theta_group = self.get_theta_group()
self.add(self.theta_group)
def add_trig_lines(self, *funcs, **kwargs):
lines = VGroup(*[
self.get_trig_line(func, **kwargs)
for func in funcs
])
self.add(*lines)
def get_theta_group(self):
arc = Arc(
self.theta_value,
radius = self.arc_radius,
color = self.theta_color,
)
theta = Tex("\\theta")
theta.shift(1.5*arc.point_from_proportion(0.5))
theta.set_color(self.theta_color)
theta.set_height(self.theta_height)
line = Line(ORIGIN, self.get_circle_point())
dot = Dot(line.get_end(), radius = 0.05)
return VGroup(line, arc, theta, dot)
def get_circle_point(self):
return rotate_vector(self.unit_length*RIGHT, self.theta_value)
def get_trig_line(self, func_name = "sin", color = None):
assert(func_name in ["sin", "tan", "sec", "cos", "cot", "csc"])
is_co = func_name in ["cos", "cot", "csc"]
if color is None:
if is_co:
color = self.y_line_colors
else:
color = self.x_line_colors
#Establish start point
if func_name in ["sin", "cos", "tan", "cot"]:
start_point = self.get_circle_point()
else:
start_point = ORIGIN
#Establish end point
if func_name is "sin":
end_point = start_point[0]*RIGHT
elif func_name is "cos":
end_point = start_point[1]*UP
elif func_name in ["tan", "sec"]:
end_point = (1./np.cos(self.theta_value))*self.unit_length*RIGHT
elif func_name in ["cot", "csc"]:
end_point = (1./np.sin(self.theta_value))*self.unit_length*UP
return Line(start_point, end_point, color = color)
class IntroduceCSC(TrigRepresentationsScene):
def construct(self):
self.clear()
Cam_S_C = TexText("Cam", "S.", "C.")
CSC = TexText("C", "S", "C", arg_separator = "")
csc_of_theta = TexText("c", "s", "c")
csc, of_theta = VGroup(*csc_of_theta[:3]), csc_of_theta[-1]
of_theta[0].set_color(YELLOW)
CSC.move_to(csc, DOWN)
csc_line = self.get_trig_line("csc")
csc_line.set_stroke(width = 8)
cot_line = self.get_trig_line("cot")
cot_line.set_color(WHITE)
brace = Brace(csc_line, LEFT)
# self.play(Write(Cam_S_C))
# self.wait()
# self.play(Transform(Cam_S_C, CSC))
# self.wait()
# self.play(Transform(Cam_S_C, csc))
# self.remove(Cam_S_C)
# self.add(csc)
# self.play(Write(of_theta))
# self.wait(2)
csc_of_theta.add_to_back(BackgroundRectangle(csc))
# self.play(
# ShowCreation(self.axes),
# ShowCreation(self.circle),
# GrowFromCenter(brace),
# csc_of_theta.rotate, np.pi/2,
# csc_of_theta.next_to, brace, LEFT,
# path_arc = np.pi/2,
# run_time = 20
# )
self.wait(4)
self.play(Write(self.theta_group, run_time = 1))
self.play(ShowCreation(cot_line))
self.play(
ShowCreation(csc_line),
csc.set_color, csc_line.get_color(),
)
self.wait(3)