Added coords_to_point and get_graph to Axes

This commit is contained in:
Grant Sanderson 2018-01-11 18:12:58 -08:00
parent ae31ee55e7
commit 32eb1a46d4

View file

@ -148,6 +148,7 @@ class Axes(VGroup):
"z_min" : -3.5, "z_min" : -3.5,
"z_max" : 3.5, "z_max" : 3.5,
"z_normal" : DOWN, "z_normal" : DOWN,
"num_graph_points" : 20,
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
VGroup.__init__(self, **kwargs) VGroup.__init__(self, **kwargs)
@ -173,6 +174,22 @@ class Axes(VGroup):
self.z_axis.rotate(angle_of_vector(self.z_normal), OUT) self.z_axis.rotate(angle_of_vector(self.z_normal), OUT)
self.add(self.z_axis) self.add(self.z_axis)
def coords_to_point(self, x, y):
origin = self.x_axis.number_to_point(0)
x_axis_projection = self.x_axis.number_to_point(x)
y_axis_projection = self.y_axis.number_to_point(y)
return x_axis_projection + y_axis_projection - origin
def get_graph(self, function, **kwargs):
kwargs["fill_opacity"] = kwargs.get("fill_opacity", 0)
graph = VMobject(**kwargs)
graph.set_points_smoothly([
self.coords_to_point(x, function(x))
for x in np.linspace(self.x_min, self.x_max)
])
return graph
class ThreeDAxes(Axes): class ThreeDAxes(Axes):
CONFIG = { CONFIG = {
"x_min" : -5.5, "x_min" : -5.5,
@ -199,7 +216,6 @@ class NumberPlane(VMobject):
"written_coordinate_height" : 0.2, "written_coordinate_height" : 0.2,
"propogate_style_to_family" : False, "propogate_style_to_family" : False,
} }
def generate_points(self): def generate_points(self):
if self.x_radius is None: if self.x_radius is None:
center_to_edge = (SPACE_WIDTH + abs(self.center_point[0])) center_to_edge = (SPACE_WIDTH + abs(self.center_point[0]))