|
27 | 27 | from manim.mobject.graphing.functions import ImplicitFunction, ParametricFunction |
28 | 28 | from manim.mobject.graphing.number_line import NumberLine |
29 | 29 | from manim.mobject.graphing.scale import LinearBase |
| 30 | +from manim.mobject.mobject import Mobject |
30 | 31 | from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL |
31 | 32 | from manim.mobject.opengl.opengl_surface import OpenGLSurface |
32 | 33 | from manim.mobject.text.tex_mobject import MathTex |
@@ -96,10 +97,10 @@ def construct(self): |
96 | 97 | ) |
97 | 98 |
|
98 | 99 | # Extra lines and labels for point (1,1) |
99 | | - graphs += grid.get_horizontal_line(grid.c2p(1, 1, 0), color=BLUE) |
100 | | - graphs += grid.get_vertical_line(grid.c2p(1, 1, 0), color=BLUE) |
101 | | - graphs += Dot(point=grid.c2p(1, 1, 0), color=YELLOW) |
102 | | - graphs += Tex("(1,1)").scale(0.75).next_to(grid.c2p(1, 1, 0)) |
| 100 | + graphs += grid.get_horizontal_line(grid @ (1, 1, 0), color=BLUE) |
| 101 | + graphs += grid.get_vertical_line(grid @ (1, 1, 0), color=BLUE) |
| 102 | + graphs += Dot(point=grid @ (1, 1, 0), color=YELLOW) |
| 103 | + graphs += Tex("(1,1)").scale(0.75).next_to(grid @ (1, 1, 0)) |
103 | 104 | title = Title( |
104 | 105 | # spaces between braces to prevent SyntaxError |
105 | 106 | r"Graphs of $y=x^{ {1}\over{n} }$ and $y=x^n (n=1,2,3,...,20)$", |
@@ -145,7 +146,7 @@ def __init__( |
145 | 146 | self.y_length = y_length |
146 | 147 | self.num_sampled_graph_points_per_tick = 10 |
147 | 148 |
|
148 | | - def coords_to_point(self, *coords: Sequence[ManimFloat]): |
| 149 | + def coords_to_point(self, *coords: ManimFloat): |
149 | 150 | raise NotImplementedError() |
150 | 151 |
|
151 | 152 | def point_to_coords(self, point: Point3D): |
@@ -570,7 +571,7 @@ def get_horizontal_line(self, point: Sequence[float], **kwargs) -> Line: |
570 | 571 | class GetHorizontalLineExample(Scene): |
571 | 572 | def construct(self): |
572 | 573 | ax = Axes().add_coordinates() |
573 | | - point = ax.c2p(-4, 1.5) |
| 574 | + point = ax @ (-4, 1.5) |
574 | 575 |
|
575 | 576 | dot = Dot(point) |
576 | 577 | line = ax.get_horizontal_line(point, line_func=Line) |
@@ -1790,6 +1791,14 @@ def construct(self): |
1790 | 1791 |
|
1791 | 1792 | return T_label_group |
1792 | 1793 |
|
| 1794 | + def __matmul__(self, coord: Point3D | Mobject): |
| 1795 | + if isinstance(coord, Mobject): |
| 1796 | + coord = coord.get_center() |
| 1797 | + return self.coords_to_point(*coord) |
| 1798 | + |
| 1799 | + def __rmatmul__(self, point: Point3D): |
| 1800 | + return self.point_to_coords(point) |
| 1801 | + |
1793 | 1802 |
|
1794 | 1803 | class Axes(VGroup, CoordinateSystem, metaclass=ConvertToOpenGL): |
1795 | 1804 | """Creates a set of axes. |
@@ -1990,6 +1999,7 @@ def coords_to_point( |
1990 | 1999 | self, *coords: float | Sequence[float] | Sequence[Sequence[float]] | np.ndarray |
1991 | 2000 | ) -> np.ndarray: |
1992 | 2001 | """Accepts coordinates from the axes and returns a point with respect to the scene. |
| 2002 | + Equivalent to `ax @ (coord1)` |
1993 | 2003 |
|
1994 | 2004 | Parameters |
1995 | 2005 | ---------- |
@@ -2018,6 +2028,8 @@ def coords_to_point( |
2018 | 2028 | >>> ax = Axes() |
2019 | 2029 | >>> np.around(ax.coords_to_point(1, 0, 0), 2) |
2020 | 2030 | array([0.86, 0. , 0. ]) |
| 2031 | + >>> np.around(ax @ (1, 0, 0), 2) |
| 2032 | + array([0.86, 0. , 0. ]) |
2021 | 2033 | >>> np.around(ax.coords_to_point([[0, 1], [1, 1], [1, 0]]), 2) |
2022 | 2034 | array([[0. , 0.75, 0. ], |
2023 | 2035 | [0.86, 0.75, 0. ], |
|
0 commit comments