コード例 #1
0
 def get_partial_points_array(self, points, a, b, resolution, axis):
     if len(points) == 0:
         return points
     nu, nv = resolution[:2]
     points = points.reshape(resolution)
     max_index = resolution[axis] - 1
     lower_index, lower_residue = integer_interpolate(0, max_index, a)
     upper_index, upper_residue = integer_interpolate(0, max_index, b)
     if axis == 0:
         points[:lower_index] = interpolate(
             points[lower_index],
             points[lower_index + 1],
             lower_residue,
         )
         points[upper_index + 1:] = interpolate(
             points[upper_index],
             points[upper_index + 1],
             upper_residue,
         )
     else:
         shape = (nu, 1, resolution[2])
         points[:, :lower_index] = interpolate(
             points[:, lower_index],
             points[:, lower_index + 1],
             lower_residue,
         ).reshape(shape)
         points[:, upper_index + 1:] = interpolate(
             points[:, upper_index],
             points[:, upper_index + 1],
             upper_residue,
         ).reshape(shape)
     return points.reshape((nu * nv, *resolution[2:]))
コード例 #2
0
    def point_to_number(self, point: Sequence[float]) -> float:
        """Accepts a point with respect to the scene and returns
        a float along the number line.

        Parameters
        ----------
        point
            A sequence of values consisting of ``(x_coord, y_coord, z_coord)``.

        Returns
        -------
        float
            A float representing a value along the number line.

        Examples
        --------

            >>> from manim import NumberLine
            >>> number_line = NumberLine()
            >>> number_line.point_to_number((0,0,0))
            0.0
            >>> number_line.point_to_number((1,0,0))
            1.0
            >>> number_line.point_to_number([[0.5,0,0],[1,0,0],[1.5,0,0]])
            array([0.5, 1. , 1.5])

        """
        point = np.asarray(point)
        start, end = self.get_start_and_end()
        unit_vect = normalize(end - start)
        proportion = np.dot(point - start, unit_vect) / np.dot(
            end - start, unit_vect)
        return interpolate(self.x_min, self.x_max, proportion)
コード例 #3
0
    def point_to_number(self, point: Sequence[float]) -> float:
        """Accepts a point with respect to the scene and returns
        a float along the number line.

        Parameters
        ----------
        point
            A sequence of values consisting of ``(x_coord, y_coord, z_coord)``.

        Returns
        -------
        float
            A float representing a value along the number line.
        """
        start, end = self.get_start_and_end()
        unit_vect = normalize(end - start)
        proportion = np.dot(point - start, unit_vect) / np.dot(
            end - start, unit_vect)
        return interpolate(self.x_min, self.x_max, proportion)
コード例 #4
0
    def number_to_point(self, number: float) -> np.ndarray:
        """Accepts a value along the number line and returns a point with
        respect to the scene.

        Parameters
        ----------
        number
            The value to be transformed into a coordinate.

        Returns
        -------
        np.ndarray
            A point with respect to the scene's coordinate system.
        """

        number = self.scaling.inverse_function(number)
        alpha = float(number - self.x_range[0]) / (self.x_range[1] -
                                                   self.x_range[0])
        val = interpolate(self.get_start(), self.get_end(), alpha)
        return val
コード例 #5
0
    def set_colors_by_radial_gradient(
        self,
        center=None,
        radius=1,
        inner_color=WHITE,
        outer_color=BLACK,
    ):
        start_rgba, end_rgba = list(
            map(color_to_rgba, [inner_color, outer_color]))
        if center is None:
            center = self.get_center()
        for mob in self.family_members_with_points():
            distances = np.abs(self.points - center)
            alphas = np.linalg.norm(distances, axis=1) / radius

            mob.rgbas = np.array(
                np.array([
                    interpolate(start_rgba, end_rgba, alpha)
                    for alpha in alphas
                ], ), )
        return self
コード例 #6
0
    def number_to_point(self, number: float | np.ndarray) -> np.ndarray:
        """Accepts a value along the number line and returns a point with
        respect to the scene.

        Parameters
        ----------
        number
            The value to be transformed into a coordinate. Or a list of values.

        Returns
        -------
        np.ndarray
            A point with respect to the scene's coordinate system. Or a list of points.

        Examples
        --------

            >>> from manim import NumberLine
            >>> number_line = NumberLine()
            >>> number_line.number_to_point(0)
            array([0., 0., 0.])
            >>> number_line.number_to_point(1)
            array([1., 0., 0.])
            >>> number_line.number_to_point([1,2,3])
            array([[1., 0., 0.],
                   [2., 0., 0.],
                   [3., 0., 0.]])
        """
        number = np.asarray(number)
        scalar = number.ndim == 0
        number = self.scaling.inverse_function(number)
        alphas = (number - self.x_range[0]) / (self.x_range[1] -
                                               self.x_range[0])
        alphas = float(alphas) if scalar else np.vstack(alphas)
        val = interpolate(self.get_start(), self.get_end(), alphas)
        return val
コード例 #7
0
 def fade_to(self, color, alpha, family=True):
     rgbas = interpolate(self.rgbas, color_to_rgba(color), alpha)
     for mob in self.submobjects:
         mob.fade_to(color, alpha, family)
     self.set_rgba_array_direct(rgbas)
     return self
コード例 #8
0
 def parameterized_function(alpha):
     x = interpolate(x_min if x_min else x_axis.x_min,
                     x_max if x_max else x_axis.x_max, alpha)
     y = f(x)
     return coords_to_point(x, y)