1
1
from manimlib .imports import *
2
2
import math as m
3
3
4
- #---- contour plot of the surface with constraint circle
5
- class ContourScene (ThreeDScene ):
4
+ class Contourplots (ThreeDScene ):
6
5
def construct (self ):
7
- axes = ThreeDAxes ().scale (0.7 ).rotate (m .radians (180 )).fade (0.6 )
6
+ axes = ThreeDAxes ().scale (0.7 ).rotate (math .radians (180 )).fade (0.6 )
8
7
label_x = TextMobject ("$x$" ).shift (4 * LEFT ).fade (0.4 ) #---- x axis
9
- label_y = TextMobject ("$y$" ).shift (3.2 * DOWN + 0.2 * RIGHT ).rotate (m .radians (180 )).fade (0.4 ) #---- y axis
8
+ label_y = TextMobject ("$y$" ).shift (3.5 * DOWN + 0.2 * RIGHT ).rotate (math .radians (180 )).fade (0.4 ) #---- y axis
10
9
11
- #---- surface of the function f(x,y) = x^2+y^2+x^3-y^3
10
+ #---- surface of the function
12
11
surface = ParametricSurface (
13
12
lambda u , v : np .array ([
14
13
u ,
15
14
v ,
16
15
u ** 2 + v ** 2 + u ** 3 - v ** 3
17
- ]),u_min = - 0.5 ,u_max = 0.5 , v_min = - 0.5 ,v_max = 0.5 ).scale (5 ).shift ([0 ,- 0.5 ,2.5 ]).set_color (TEAL ).fade (0.5 )
18
-
16
+ ]),u_min = - 0.5 ,u_max = 0.5 , v_min = - 0.5 ,v_max = 0.5 ).scale (6 ).shift ([0 ,0 ,2.5 ]).set_color (TEAL ).fade (0.5 )
19
17
20
- #---- contour plots of the surface of the function
18
+ #---- contour plots
19
+ curve1 = ParametricSurface (
20
+ lambda u , v : np .array ([
21
+ u * 0.4 ,
22
+ m .exp (m .sin (v ** 2 )),
23
+ - v * 2.2
24
+ ]),v_min = - 1.3 , v_max = 1.3 , u_min = - 0.1 , u_max = 0.1 ).scale (0.8 ).shift ([0 ,- 2.65 ,0 ]).set_color ("#800000" ).rotate (1.2 ,DOWN )
21
25
22
- c0 = Circle (color = '#800000' ).scale (0.5 ).shift ([0 ,- 0.5 ,0 ])
23
- c1 = Circle (color = '#800000' ).scale (1 ).shift ([0 ,- 0.5 ,0 ])
24
- c2 = Circle (color = '#800000' ).scale (1.5 ).shift ([0 ,- 0.5 ,0 ])
25
- c3 = Circle (color = '#800000' ).scale (2 ).shift ([0 ,- 0.5 ,0 ])
26
- c4 = Circle (color = '#800000' ).scale (2.5 ).shift ([0 ,- 0.5 ,0 ])
26
+ curve2 = ParametricSurface (
27
+ lambda u , v : np .array ([
28
+ u * 0.4 ,
29
+ m .exp (m .sin (v ** 2 )),
30
+ - v * 2.2
31
+ ]),v_min = - 1.3 , v_max = 1.3 , u_min = - 0.1 , u_max = 0.1 ).scale (0.9 ).shift ([0 ,- 3 ,0 ]).set_color ("#800000" ).rotate (1.2 ,DOWN )
27
32
28
- #---- constraint circle
29
- circle = Circle (color = '#FF00FF' ,fill_opacity = 0.3 ).shift ([- 0.5 ,- 1.2 ,1.5 ]).rotate (1.9 ,UP ).scale (0.8 )
30
- circle2 = Circle (color = '#FF00FF' ,fill_opacity = 0.3 ).shift ([0.74 ,0.95 ,1.5 ]).rotate (1.9 ,UP ).scale (0.8 )
33
+ curve3 = ParametricSurface (
34
+ lambda u , v : np .array ([
35
+ u * 0.4 ,
36
+ m .exp (m .sin (v ** 2 )),
37
+ - v * 2.2
38
+ ]),v_min = - 1.3 , v_max = 1.3 , u_min = - 0.1 , u_max = 0.1 ).scale (1 ).shift ([0 ,- 3.5 ,0 ]).set_color ("#800000" ).rotate (1.2 ,DOWN )
39
+
40
+ curve4 = ParametricSurface (
41
+ lambda u , v : np .array ([
42
+ u * 0.4 ,
43
+ m .exp (m .sin (v ** 2 )),
44
+ - v * 2.2
45
+ ]),v_min = - 1.3 , v_max = 1.3 , u_min = - 0.1 , u_max = 0.1 ).scale (1.1 ).shift ([0 ,- 4 ,0 ]).set_color ("#800000" ).rotate (1.2 ,DOWN )
46
+
47
+ curve5 = ParametricSurface (
48
+ lambda u , v : np .array ([
49
+ u * 0.4 ,
50
+ - m .exp (m .sin (v ** 2 )),
51
+ v * 2.2
52
+ ]),v_min = - 1.3 , v_max = 1.3 , u_min = - 0.1 , u_max = 0.1 ).scale (0.9 ).shift ([0 ,3 ,0 ]).set_color ("#800000" ).rotate (1.2 ,DOWN )
53
+
54
+ curve6 = ParametricSurface (
55
+ lambda u , v : np .array ([
56
+ u * 0.4 ,
57
+ - m .exp (m .sin (v ** 2 )),
58
+ v * 2.2
59
+ ]),v_min = - 1.3 , v_max = 1.3 , u_min = - 0.1 , u_max = 0.1 ).scale (1 ).shift ([0 ,3.5 ,0 ]).set_color ("#800000" ).rotate (1.2 ,DOWN )
60
+
61
+ curve7 = ParametricSurface (
62
+ lambda u , v : np .array ([
63
+ u * 0.4 ,
64
+ - m .exp (m .sin (v ** 2 )),
65
+ v * 2.2
66
+ ]),v_min = - 1.3 , v_max = 1.3 , u_min = - 0.1 , u_max = 0.1 ).scale (1.1 ).shift ([0 ,4 ,0 ]).set_color ("#800000" ).rotate (1.2 ,DOWN )
67
+
68
+ curve8 = ParametricSurface (
69
+ lambda u , v : np .array ([
70
+ u * 0.4 ,
71
+ - m .exp (m .sin (v ** 2 )),
72
+ v * 2.2
73
+ ]),v_min = - 1.3 , v_max = 1.3 , u_min = - 0.1 , u_max = 0.1 ).scale (0.8 ).shift ([0 ,2.65 ,0 ]).set_color ("#800000" ).rotate (1.2 ,DOWN )
31
74
32
- maxima = Dot (color = '#4169E1' ).shift ([0.7 ,0.15 ,1.5 ]) #---- point of maxima
33
- minima = Dot (color = '#4169E1' ).shift ([0.8 ,1.7 ,1.5 ]) #---- point of minima
75
+ #---------------
76
+
77
+ #---- label contours
78
+ label_c1 = TextMobject ("4" ,color = '#FFA074' ).shift ([0.2 ,3 ,0.5 ]).scale (0.5 ).rotate (m .radians (180 ))
79
+ label_c2 = TextMobject ("3" ,color = '#FFA074' ).shift ([0.2 ,2.4 ,0.5 ]).scale (0.5 ).rotate (m .radians (180 ))
80
+ label_c3 = TextMobject ("2" ,color = '#FFA074' ).shift ([0.2 ,1.9 ,0.5 ]).scale (0.5 ).rotate (m .radians (180 ))
81
+ label_c4 = TextMobject ("1" ,color = '#FFA074' ).shift ([0.2 ,1.4 ,0.5 ]).scale (0.5 ).rotate (m .radians (180 ))
82
+ label_c5 = TextMobject ("1" ,color = '#FFA074' ).shift ([0.2 ,- 1.5 ,0.5 ]).scale (0.5 ).rotate (m .radians (180 ))
83
+ label_c6 = TextMobject ("2" ,color = '#FFA074' ).shift ([0.2 ,- 2 ,0.5 ]).scale (0.5 ).rotate (m .radians (180 ))
84
+ label_c7 = TextMobject ("3" ,color = '#FFA074' ).shift ([0.2 ,- 2.5 ,0.5 ]).scale (0.5 ).rotate (m .radians (180 ))
85
+ label_c8 = TextMobject ("4" ,color = '#FFA074' ).shift ([0.2 ,- 3 ,0.5 ]).scale (0.5 ).rotate (m .radians (180 ))
86
+
87
+ contourplot = VGroup (curve1 ,curve2 ,curve3 ,curve4 ,curve5 ,curve6 ,curve7 ,curve8 ,label_c1 ,label_c2 ,label_c3 ,label_c4 ,label_c5 ,label_c6 ,label_c7 ,label_c8 )
88
+
34
89
35
- min_text = TextMobject ("minimum over $g(x,y)=k$" ,color = '#FFA074' ).scale (0.6 ).shift ([- 2 ,0.16 ,1.5 ])
36
- max_text = TextMobject ("maximum over $g(x,y)=k$" ,color = '#FFA074' ).shift ([- 2.3 ,- 2.6 ,1.5 ]).scale (0.6 ).shift (0.5 * UP )
90
+ circle = Circle (color = '#FF00FF' ,fill_opacity = 0.3 ).shift ([- 0.5 ,- 1.2 ,1.5 ]).rotate (1.9 ,UP ).scale (0.8 )
91
+ circle2 = ParametricSurface (
92
+ lambda u , v : np .array ([
93
+ 1 * np .sin (u )* np .cos (v ),
94
+ 1 * np .sin (u )* np .sin (v ),
95
+ - 1 * np .sin (u )* np .sin (u )+ 2
96
+ ]),u_min = 0 ,u_max = PI / 2 ,v_min = 0 ,v_max = 2 * PI ).set_color ('#FF00FF' ).scale (0.6 ).shift ([1.2 ,2 ,- 3 ]).scale (1.24 )
37
97
98
+ maxima = Dot (color = '#4169E1' ).shift ([0.7 ,1.2 ,1.5 ])
99
+ minima = Dot (color = '#4169E1' ).shift ([1.4 ,2.2 ,1.5 ])
38
100
39
- #---- labelling contour curves
40
- label_c0 = TextMobject ("1" ,color = '#FFA074' ).shift ([0.2 ,0.1 ,0.5 ]).scale (0.5 )
41
- label_c1 = TextMobject ("2" ,color = '#FFA074' ).shift ([0.2 ,- 0.6 ,0.5 ]).scale (0.5 )
42
- label_c2 = TextMobject ("3" ,color = '#FFA074' ).shift ([0.2 ,- 1.1 ,0.5 ]).scale (0.5 )
43
- label_c3 = TextMobject ("4" ,color = '#FFA074' ).shift ([0.2 ,- 1.6 ,0.5 ]).scale (0.5 )
44
- label_c4 = TextMobject ("5" ,color = '#FFA074' ).shift ([0.2 ,- 2.1 ,0.5 ]).scale (0.5 )
101
+ min_text = TextMobject ("minimum over $g(x,y)=k$" ,color = '#FFA074' ).scale (0.6 ).shift ([- 2.2 ,- 1 ,1.5 ])
102
+ max_text = TextMobject ("maximum over $g(x,y)=k$" ,color = '#FFA074' ).shift ([- 2.3 ,- 2.6 ,1.5 ]).scale (0.6 )
45
103
46
104
47
105
self .set_camera_orientation (phi = 75 * DEGREES , theta = 45 * DEGREES )
@@ -56,15 +114,10 @@ def construct(self):
56
114
self .wait (1 )
57
115
self .move_camera (phi = 0 * DEGREES , theta = 90 * DEGREES )
58
116
self .wait (1 )
59
- self .play (Write (c0 ),Write (c1 ),Write (c2 ),Write (c3 ),Write (c4 ))
60
- self .play (FadeOut (surface ))
61
- self .add_fixed_in_frame_mobjects (label_c0 )
62
- self .add_fixed_in_frame_mobjects (label_c1 )
63
- self .add_fixed_in_frame_mobjects (label_c2 )
64
- self .add_fixed_in_frame_mobjects (label_c3 )
65
- self .add_fixed_in_frame_mobjects (label_c4 )
117
+ self .add (contourplot )
118
+ self .play (FadeOut (surface ))
66
119
self .wait (1 )
67
- self .play ( Write ( circle2 ))
120
+ self .add ( circle2 )
68
121
self .wait (1 )
69
122
self .play (Write (minima ),Write (maxima ))
70
123
self .add_fixed_in_frame_mobjects (max_text )
0 commit comments