2016-01-04 10:15:39 -08:00
|
|
|
from scipy import integrate
|
2015-10-27 21:00:50 -07:00
|
|
|
|
2016-04-19 00:20:19 -07:00
|
|
|
from mobject.vectorized_mobject import VMobject
|
2015-10-27 21:00:50 -07:00
|
|
|
|
2016-01-04 10:15:39 -08:00
|
|
|
from helpers import *
|
2015-10-27 21:00:50 -07:00
|
|
|
|
2016-04-19 00:20:19 -07:00
|
|
|
class FunctionGraph(VMobject):
|
2016-02-27 16:32:53 -08:00
|
|
|
CONFIG = {
|
2016-04-19 00:20:19 -07:00
|
|
|
"color" : BLUE_D,
|
|
|
|
"x_min" : -SPACE_WIDTH,
|
|
|
|
"x_max" : SPACE_WIDTH,
|
2016-07-12 15:16:20 -07:00
|
|
|
"num_steps" : 20,
|
2015-10-27 21:00:50 -07:00
|
|
|
}
|
|
|
|
def __init__(self, function, **kwargs):
|
2015-10-28 16:03:33 -07:00
|
|
|
self.function = function
|
2016-04-19 00:20:19 -07:00
|
|
|
VMobject.__init__(self, **kwargs)
|
2015-10-27 21:00:50 -07:00
|
|
|
|
|
|
|
def generate_points(self):
|
2016-04-19 00:20:19 -07:00
|
|
|
self.set_anchor_points([
|
|
|
|
x*RIGHT + self.function(x)*UP
|
2016-07-12 15:16:20 -07:00
|
|
|
for x in np.linspace(self.x_min, self.x_max, self.num_steps)
|
2016-04-19 00:20:19 -07:00
|
|
|
], mode = "smooth")
|
2015-10-27 21:00:50 -07:00
|
|
|
|
2016-09-16 14:06:44 -07:00
|
|
|
def get_function(self):
|
|
|
|
return self.function
|
|
|
|
|
2015-10-27 21:00:50 -07:00
|
|
|
|
2016-04-19 00:20:19 -07:00
|
|
|
class ParametricFunction(VMobject):
|
2016-02-27 16:32:53 -08:00
|
|
|
CONFIG = {
|
2016-04-19 00:20:19 -07:00
|
|
|
"t_min" : 0,
|
|
|
|
"t_max" : 1,
|
|
|
|
"epsilon" : 0.1,
|
2015-10-27 21:00:50 -07:00
|
|
|
}
|
|
|
|
def __init__(self, function, **kwargs):
|
2015-10-28 16:03:33 -07:00
|
|
|
self.function = function
|
2016-04-19 00:20:19 -07:00
|
|
|
VMobject.__init__(self, **kwargs)
|
2015-10-27 21:00:50 -07:00
|
|
|
|
|
|
|
def generate_points(self):
|
2016-04-19 00:20:19 -07:00
|
|
|
self.set_anchor_points([
|
|
|
|
self.function(t)
|
2016-04-27 17:35:04 -07:00
|
|
|
for t in np.arange(
|
|
|
|
self.t_min,
|
|
|
|
self.t_max+self.epsilon,
|
|
|
|
self.epsilon
|
|
|
|
)
|
2016-04-19 00:20:19 -07:00
|
|
|
], mode = "smooth")
|
|
|
|
|
|
|
|
|
2015-10-28 16:03:33 -07:00
|
|
|
|
|
|
|
|