2018-03-31 19:05:53 -07:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
from constants import *
|
2015-10-27 21:00:50 -07:00
|
|
|
|
2018-03-31 18:05:02 -07:00
|
|
|
from mobject.types.vectorized_mobject import VMobject
|
2018-03-30 18:19:23 -07:00
|
|
|
from utils.config_ops import digest_config
|
2015-10-27 21:00:50 -07:00
|
|
|
|
|
|
|
|
2018-01-18 16:46:38 -08:00
|
|
|
class ParametricFunction(VMobject):
|
2016-02-27 16:32:53 -08:00
|
|
|
CONFIG = {
|
2018-01-18 16:46:38 -08:00
|
|
|
"t_min" : 0,
|
|
|
|
"t_max" : 1,
|
|
|
|
"num_anchor_points" : 100,
|
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):
|
2018-01-18 16:46:38 -08:00
|
|
|
n_points = 3*self.num_anchor_points - 2
|
|
|
|
self.points = np.zeros((n_points, self.dim))
|
|
|
|
self.points[:,0] = np.linspace(
|
|
|
|
self.t_min, self.t_max, n_points
|
|
|
|
)
|
|
|
|
#VMobject.apply_function takes care of preserving
|
|
|
|
#desirable tangent line properties at anchor points
|
|
|
|
self.apply_function(lambda p : self.function(p[0]))
|
2015-10-27 21:00:50 -07:00
|
|
|
|
2018-01-18 16:46:38 -08:00
|
|
|
class FunctionGraph(ParametricFunction):
|
2016-02-27 16:32:53 -08:00
|
|
|
CONFIG = {
|
2018-01-18 16:46:38 -08:00
|
|
|
"color" : YELLOW,
|
2018-03-30 11:25:37 -07:00
|
|
|
"x_min" : -FRAME_X_RADIUS,
|
|
|
|
"x_max" : FRAME_X_RADIUS,
|
2015-10-27 21:00:50 -07:00
|
|
|
}
|
|
|
|
def __init__(self, function, **kwargs):
|
2018-01-18 16:46:38 -08:00
|
|
|
digest_config(self, kwargs)
|
|
|
|
parametric_function = lambda t : t*RIGHT + function(t)*UP
|
|
|
|
ParametricFunction.__init__(
|
|
|
|
self,
|
|
|
|
parametric_function,
|
|
|
|
t_min = self.x_min,
|
|
|
|
t_max = self.x_max,
|
|
|
|
**kwargs
|
|
|
|
)
|
2015-10-28 16:03:33 -07:00
|
|
|
self.function = function
|
2015-10-27 21:00:50 -07:00
|
|
|
|
2018-01-18 16:46:38 -08:00
|
|
|
def get_function(self):
|
|
|
|
return self.function
|
|
|
|
|
2017-03-14 15:50:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-19 00:20:19 -07:00
|
|
|
|
|
|
|
|
2015-10-28 16:03:33 -07:00
|
|
|
|