-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
158 lines (128 loc) · 6.11 KB
/
test.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from manim import *
# manim -p -ql test.py ParallelogramWithDetails
class SquareToCircle(Scene):
def construct(self):
circle = Circle()
square = Square()
square.flip(RIGHT)
square.rotate(-3 * TAU / 8)
circle.set_fill(PINK, opacity=0.5)
self.play(Create(square))
self.play(Transform(square, circle))
self.play(FadeOut(square))
class ParallelogramWithDetails(Scene):
def construct(self):
# Define the vertices of the parallelogram
A = [-3, -1, 0] # Coordinates for A
B = [1, -1, 0] # Coordinates for B
C = [3, 1, 0] # Coordinates for C
D = [-1, 1, 0] # Coordinates for D
# Create points
point_A = Dot(A, color=BLUE)
point_B = Dot(B, color=BLUE)
point_C = Dot(C, color=BLUE)
point_D = Dot(D, color=BLUE)
# Create labels for points
label_A = MathTex("A(-3, -1)").next_to(point_A, DOWN)
label_B = MathTex("B(1, -1)").next_to(point_B, DOWN)
label_C = MathTex("C(3, 1)").next_to(point_C, UP)
label_D = MathTex("D(-1, 1)").next_to(point_D, UP)
# Create lines between points
line_AB = Line(A, B)
line_BC = Line(B, C)
line_CD = Line(C, D)
line_DA = Line(D, A)
# Create edge lengths
length_AB = MathTex("4").next_to(line_AB, DOWN)
length_BC = MathTex("2\\sqrt{5}").next_to(line_BC, RIGHT)
length_CD = MathTex("4").next_to(line_CD, UP)
length_DA = MathTex("2\\sqrt{5}").next_to(line_DA, LEFT)
# Draw the parallelogram, labels, and edge lengths at once
self.add(point_A, point_B, point_C, point_D)
self.add(label_A, label_B, label_C, label_D)
self.add(line_AB, line_BC, line_CD, line_DA)
self.add(length_AB, length_BC, length_CD, length_DA)
# Wait for a moment at the end to keep everything displayed
self.wait(2)
# class ParallelogramWithDetailsAndAngles(Scene):
# def construct(self):
# # Define the vertices of the parallelogram
# A = [-3, -1, 0] # Coordinates for A
# B = [1, -1, 0] # Coordinates for B
# C = [3, 1, 0] # Coordinates for C
# D = [-1, 1, 0] # Coordinates for D
# # Create points
# point_A = Dot(A, color=BLUE)
# point_B = Dot(B, color=BLUE)
# point_C = Dot(C, color=BLUE)
# point_D = Dot(D, color=BLUE)
# # Create labels for points
# label_A = MathTex("A(-3, -1)").next_to(point_A, DOWN)
# label_B = MathTex("B(1, -1)").next_to(point_B, DOWN)
# label_C = MathTex("C(3, 1)").next_to(point_C, UP)
# label_D = MathTex("D(-1, 1)").next_to(point_D, UP)
# # Create lines between points
# line_AB = Line(A, B)
# line_BC = Line(B, C)
# line_CD = Line(C, D)
# line_DA = Line(D, A)
# # Create edge lengths
# length_AB = MathTex("4").next_to(line_AB, DOWN)
# length_BC = MathTex("2\\sqrt{5}").next_to(line_BC, RIGHT)
# length_CD = MathTex("4").next_to(line_CD, UP)
# length_DA = MathTex("2\\sqrt{5}").next_to(line_DA, LEFT)
# # Calculate and display angles (approximated for simplicity)
# angle_A = MathTex("120^\\circ").next_to(A , np.array((1.0, 1.0, 0)))
# angle_B = MathTex("60^\\circ").next_to(B , np.array((-1.0, 1.0, 0)))
# angle_C = MathTex("120^\\circ").next_to(C , np.array((-1.0, -1.0, 0)))
# angle_D = MathTex("60^\\circ").next_to(D , np.array((1.0, -1.0, 0)))
# self.add(angle_A, angle_B, angle_C, angle_D)
# # self.add(angle_A)
# # Draw the parallelogram, labels, edge lengths, and angles at once
# self.add(point_A, point_B, point_C, point_D)
# self.add(label_A, label_B, label_C, label_D)
# self.add(line_AB, line_BC, line_CD, line_DA)
# self.add(length_AB, length_BC, length_CD, length_DA)
# # Wait for a moment at the end to keep everything displayed
# self.wait(2)
class ParallelogramWithDetailsAndAngles(Scene):
def __init__(self, vertices, angles, edge_lengths, **kwargs):
super().__init__(**kwargs)
self.vertices = vertices
self.angles = angles
self.edge_lengths = edge_lengths
def construct(self):
A, B, C, D = self.vertices # Unpack the vertex coordinates
# Create points
point_A = Dot(A, color=BLUE)
point_B = Dot(B, color=BLUE)
point_C = Dot(C, color=BLUE)
point_D = Dot(D, color=BLUE)
# Create labels for points
label_A = MathTex(f"A({A[0]}, {A[1]})").next_to(point_A, DOWN)
label_B = MathTex(f"B({B[0]}, {B[1]})").next_to(point_B, DOWN)
label_C = MathTex(f"C({C[0]}, {C[1]})").next_to(point_C, UP)
label_D = MathTex(f"D({D[0]}, {D[1]})").next_to(point_D, UP)
# Create lines between points
line_AB = Line(A, B)
line_BC = Line(B, C)
line_CD = Line(C, D)
line_DA = Line(D, A)
# Create edge lengths (values are passed as parameters)
length_AB = MathTex(f"{self.edge_lengths[0]}").next_to(line_AB, DOWN)
length_BC = MathTex(f"{self.edge_lengths[1]}").next_to(line_BC, RIGHT)
length_CD = MathTex(f"{self.edge_lengths[2]}").next_to(line_CD, UP)
length_DA = MathTex(f"{self.edge_lengths[3]}").next_to(line_DA, LEFT)
# Create angles (values are passed as parameters)
angle_A = MathTex(f"{self.angles[0]}^\\circ").next_to(A, np.array((1.0, 1.0, 0)))
angle_B = MathTex(f"{self.angles[1]}^\\circ").next_to(B, np.array((-1.0, 1.0, 0)))
angle_C = MathTex(f"{self.angles[2]}^\\circ").next_to(C, np.array((-1.0, -1.0, 0)))
angle_D = MathTex(f"{self.angles[3]}^\\circ").next_to(D, np.array((1.0, -1.0, 0)))
# Draw everything at once
self.add(point_A, point_B, point_C, point_D)
self.add(label_A, label_B, label_C, label_D)
self.add(line_AB, line_BC, line_CD, line_DA)
self.add(length_AB, length_BC, length_CD, length_DA)
self.add(angle_A, angle_B, angle_C, angle_D)
# Wait for a moment at the end to keep everything displayed
self.wait(2)