
    lj:                    V   d Z ddlmZ g dZddlmZmZmZ ddlm	Z	m
Z
mZmZ ddlZddlmZmZ ddlT dd	lmZ dd
lmZ ddlT ddlmZ ddlmZ ddlmZmZmZ ddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z, e	rddl-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3  G d dee          Z4 G d dee          Z5 G d de5          Z6 G d de6          Z7 G d de          Z8 G d de8          Z9 G d d e5          Z: G d! d"e5          Z; G d# d$e;          Z< G d% d&e<          Z= G d' d(e5          Z>dS ))zThree-dimensional mobjects.    )annotations)ThreeDVMobjectSurfaceSphereDot3DCubePrismConeArrow3DCylinderLine3DTorus)CallableIterableSequence)TYPE_CHECKINGAnyLiteralSelfN)configlogger)*)Circle)Square)ConvertToOpenGL)OpenGLMobject)VectorizedPointVGroupVMobject)BLUEBLUE_DBLUE_E
LIGHT_GREYWHITE
ManimColorParsableManimColorinterpolate_color)	normalizeperpendicular_bisectorz_to_vector)
ThreeDAxes)Point3DPoint3DLikeVector3DVector3DLikec                  `     e Zd ZU ded<   ded<   ded<   ded<   ded<   ded<   dd fdZ xZS )r   intu_indexv_indexfloatu1u2v1v2Tshade_in_3dboolkwargsr   c                >     t                      j        dd|i| d S )Nr9    )super__init__)selfr9   r;   	__class__s      a/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/three_d/three_dimensions.pyr?   zThreeDVMobject.__init__9   s+    ;;[;F;;;;;    )T)r9   r:   r;   r   )__name__
__module____qualname____annotations__r?   __classcell__rA   s   @rB   r   r   1   sz         LLLLLLIIIIIIIIIIII< < < < < < < < < < <rC   r   )	metaclassc                  t     e Zd ZdZdddi edeegedddfd7 fd Zd8d$Zd9d&Z	d:d'Z
d(d)d;d.Z	 	 d<d=d6Z xZS )>r   u(  Creates a Parametric Surface using a checkerboard pattern.

    Parameters
    ----------
    func
        The function defining the :class:`Surface`.
    u_range
        The range of the ``u`` variable: ``(u_min, u_max)``.
    v_range
        The range of the ``v`` variable: ``(v_min, v_max)``.
    resolution
        The number of samples taken of the :class:`Surface`. A tuple can be
        used to define different resolutions for ``u`` and ``v`` respectively.
    fill_color
        The color of the :class:`Surface`. Ignored if ``checkerboard_colors``
        is set.
    fill_opacity
        The opacity of the :class:`Surface`, from 0 being fully transparent
        to 1 being fully opaque. Defaults to 1.
    checkerboard_colors
        ng individual faces alternating colors. Overrides ``fill_color``.
    stroke_color
        Color of the stroke surrounding each face of :class:`Surface`.
    stroke_width
        Width of the stroke surrounding each face of :class:`Surface`.
        Defaults to 0.5.
    should_make_jagged
        Changes the anchor mode of the Bézier curves from smooth to jagged.
        Defaults to ``False``.

    Examples
    --------
    .. manim:: ParaSurface
        :save_last_frame:

        class ParaSurface(ThreeDScene):
            def func(self, u, v):
                return np.array([np.cos(u) * np.cos(v), np.cos(u) * np.sin(v), u])

            def construct(self):
                axes = ThreeDAxes(x_range=[-4,4], x_length=8)
                surface = Surface(
                    lambda u, v: axes.c2p(*self.func(u, v)),
                    u_range=[-PI, PI],
                    v_range=[0, TAU],
                    resolution=8,
                )
                self.set_camera_orientation(theta=70 * DEGREES, phi=75 * DEGREES)
                self.add(axes, surface)
    )r          g      ?g      ?Fgh㈵>func$Callable[[float, float], np.ndarray]u_rangetuple[float, float]v_range
resolutionint | Sequence[int]surface_piece_configdict
fill_colorr&   fill_opacityr4   checkerboard_colors-Iterable[ParsableManimColor] | Literal[False]stroke_colorstroke_widthshould_make_jaggedr:   *pre_function_handle_to_anchor_scale_factorr;   r   returnNonec                x   || _         || _         t                      j        d|||	|
d| || _        || _        |  |du r|| _        nd |D             | _        || _        || _        | _	        | 
                                 |                     fd           | j        r|                                  d S d S )N)rW   rX   r[   r\   Fc                ,    g | ]}t          |          S r=   r%   .0is     rB   
<listcomp>z$Surface.__init__.<locals>.<listcomp>   s    'S'S'S!
1'S'S'SrC   c                4     | d         | d                   S )Nr   rL   r=   )prN   s    rB   <lambda>z"Surface.__init__.<locals>.<lambda>   s    dd1Q41&6&6 rC   r=   )rP   rR   r>   r?   rS   rU   rY   r]   r^   _func_setup_in_uv_spaceapply_functionmake_jagged)r@   rN   rP   rR   rS   rU   rW   rX   rY   r[   r\   r]   r^   r;   rA   s    `            rB   r?   zSurface.__init__q   s   &  	
!%%%		
 	

 	
 	
 	
 %$8!C%''':D$$'S'S?R'S'S'SD$"46 	7 
!!!6666777" 		 	rC   uv
np.ndarrayc                .    |                      ||          S N)rk   r@   ro   rp   s      rB   rN   zSurface.func   s    zz!QrC   tuple[np.ndarray, np.ndarray]c                    t          | j        t                    r
| j        x}}n
| j        \  }}t          j        g | j        |dz   R  }t          j        g | j        |dz   R  }||fS )NrL   )
isinstancerS   r1   nplinspacerP   rR   )r@   u_resv_resu_valuesv_valuess        rB   _get_u_values_and_v_valuesz"Surface._get_u_values_and_v_values   sz    dos++ 	+ O+EEE?LE5;88eai888;88eai888!!rC   c                   |                                  \  }}t                      }t          t          |          dz
            D ]}t          t          |          dz
            D ]}|||dz            \  }}|||dz            \  }}	t	                      }
|
                    ||dg||dg||	dg||	dg||dgg           |                    |
           ||
_        ||
_        ||
_	        ||
_
        ||
_        |	|
_        |                    | j        | j                   |                    | j        | j        | j                    | j        |  | j        r | j        | j          d S d S )NrL      r   )coloropacity)r   widthr   )r~   r   rangelenr   set_points_as_cornersaddr2   r3   r5   r6   r7   r8   set_fillrW   rX   
set_stroker[   r\   stroke_opacityrY   set_fill_by_checkerboard)r@   r|   r}   facesrf   jr5   r6   r7   r8   faces              rB   rl   zSurface._setup_in_uv_space   s   !<<>>(s8}}q()) 	 	A3x==1,--  !!a!e),B!!a!e),B%''**RRRRR   		$  '( 	T_d6GHHH##' 	 	
 	
 	

 	%# 	E)D)4+CDDDD	E 	ErC   Nr   colorsr   float | Noner   c                   t          |          }| D ]1}|j        |j        z   |z  }|                    ||         |           2| S )a  Sets the fill_color of each face of :class:`Surface` in
        an alternating pattern.

        Parameters
        ----------
        colors
            List of colors for alternating pattern.
        opacity
            The fill_opacity of :class:`Surface`, from 0 being fully transparent
            to 1 being fully opaque.

        Returns
        -------
        :class:`~.Surface`
            The parametric surface with an alternating pattern.
        r   )r   r2   r3   r   )r@   r   r   n_colorsr   c_indexs         rB   r   z Surface.set_fill_by_checkerboard   sS    & v;; 	< 	<D|dl2h>GMM&/7M;;;;rC   r   axesr+   
colorscalePIterable[ParsableManimColor] | Iterable[tuple[ParsableManimColor, float]] | Noneaxisr1   c                   d|v rH|F|                     d          }|r/t          dd                    d |D                                  |t          j        d           | S t          |          }|j        |j        |j        g}t          |t
                    sJ t          |d                   t          u r5t          |d                   dk    rd	 |D             d
 |D             g\  }}nZd |D             }||         }	|	J |	d         }
|	d         }||
z
  t          |          dz
  z  }t          j        |
||z   |          }|                                 D ]j}|                    |                                          |         }||d         k    r|                    |d                    X||d         k    r|                    |d                    t'          |          D ]\  }}||k    r|||dz
           z
  ||         ||dz
           z
  z  }t)          |d          }t+          ||dz
           ||         |          }t,          j        t0          j        k    r/t          |t4                    sJ |                    |d           n1t,          j        t0          j        k    r|                    |d            nېl| S )aY  Sets the color of each mobject of a parametric surface to a color
        relative to its axis-value.

        Parameters
        ----------
        axes
            The axes for the parametric surface, which will be used to map
            axis-values to colors.
        colorscale
            A list of colors, ordered from lower axis-values to higher axis-values.
            If a list of tuples is passed containing colors paired with numbers,
            then those numbers will be used as the pivots.
        axis
            The chosen axis to use for the color mapping. (0 = x, 1 = y, 2 = z)

        Returns
        -------
        :class:`~.Surface`
            The parametric surface with a gradient applied by value. For chaining.

        Examples
        --------
        .. manim:: FillByValueExample
            :save_last_frame:

            class FillByValueExample(ThreeDScene):
                def construct(self):
                    resolution_fa = 8
                    self.set_camera_orientation(phi=75 * DEGREES, theta=-160 * DEGREES)
                    axes = ThreeDAxes(x_range=(0, 5, 1), y_range=(0, 5, 1), z_range=(-1, 1, 0.5))
                    def param_surface(u, v):
                        x = u
                        y = v
                        z = np.sin(x) * np.cos(y)
                        return z
                    surface_plane = Surface(
                        lambda u, v: axes.c2p(u, v, param_surface(u, v)),
                        resolution=(resolution_fa, resolution_fa),
                        v_range=[0, 5],
                        u_range=[0, 5],
                        )
                    surface_plane.set_style(fill_opacity=1)
                    surface_plane.set_fill_by_value(axes=axes, colorscale=[(RED, -0.5), (YELLOW, 0), (GREEN, 0.5)], axis=2)
                    self.add(axes, surface_plane)
        r   Nz!Unsupported keyword argument(s): z, c              3  4   K   | ]}t          |          V  d S rs   )str)re   keys     rB   	<genexpr>z,Surface.set_fill_by_value.<locals>.<genexpr>"  s(       < <cS < < < < < <rC   ziThe value passed to the colorscale keyword argument was None, the surface fill color has not been changedr   r   c                2    g | ]\  }}t          |          S r=   rc   re   rf   r   s      rB   rg   z-Surface.set_fill_by_value.<locals>.<listcomp>1  s"    ;;;41aA;;;rC   c                    g | ]\  }}|S r=   r=   r   s      rB   rg   z-Surface.set_fill_by_value.<locals>.<listcomp>2  s    ///tq!///rC   c                ,    g | ]}t          |          S r=   rc   rd   s     rB   rg   z-Surface.set_fill_by_value.<locals>.<listcomp>5  s    AAAA*Q--AAArC   rL   )startstopstepF)recurse)family)pop
ValueErrorjoinr   warninglistx_rangey_rangez_rangerw   typetupler   rx   arangefamily_members_with_pointspoint_to_coordsget_midpoint	set_color	enumerateminr'   r   rendererRendererTypeOPENGLr   CAIRO)r@   r   r   r   r;   colorscale_listranges
new_colorspivotscurrent_range	pivot_min	pivot_maxpivot_frequencymob
axis_valuerf   pivotcolor_index	mob_colors                      rB   set_fill_by_valuezSurface.set_fill_by_value   s7   l v*"4H--J  ?yy < <V < < <<<? ?   N>   Kz**,dl;/400000"##u,,_Q5G1H1HA1M1M;;?;;;/////"J
 BAAAAJ"4LM ,,,%a(I%a(I(94Z19LMOY0$  F 2244 	 	C--c.>.>.@.@AA$GJVAY&&jm,,,,vbz))jn---- )& 1 1  HAuz))'1F1q5M'A"1Iq1u5' '*+q&9&9$5&q1u-&qM'% %	
 "?l.AAA#-c=#A#AAA#AMM)UMCCCC#_0BBBMM)EMBBB *" rC   )rN   rO   rP   rQ   rR   rQ   rS   rT   rU   rV   rW   r&   rX   r4   rY   rZ   r[   r&   r\   r4   r]   r:   r^   r4   r;   r   r_   r`   ro   r4   rp   r4   r_   rq   )r_   ru   r_   r`   )r   r&   r   r   r_   r   )Nr   )
r   r+   r   r   r   r1   r;   r   r_   r   )rD   rE   rF   __doc__r!   r"   r#   r?   rN   r~   rl   r   r   rH   rI   s   @rB   r   r   =   s       1 1l (.'-*,%')/!N
 ,6!#(<C!+ + + + + + +Z       	" 	" 	" 	" E  E  E  EF DH     < t t t t t t t t trC   r   c                  @     e Zd ZdZedddefdeffd fdZddZ xZ	S )r   aC  A three-dimensional sphere.

    Parameters
    ----------
    center
        Center of the :class:`Sphere`.
    radius
        The radius of the :class:`Sphere`.
    resolution
        The number of samples taken of the :class:`Sphere`. A tuple can be used
        to define different resolutions for ``u`` and ``v`` respectively.
    u_range
        The range of the ``u`` variable: ``(u_min, u_max)``.
    v_range
        The range of the ``v`` variable: ``(v_min, v_max)``.

    Examples
    --------

    .. manim:: ExampleSphere
        :save_last_frame:

        class ExampleSphere(ThreeDScene):
            def construct(self):
                self.set_camera_orientation(phi=PI / 6, theta=PI / 6)
                sphere1 = Sphere(
                    center=(3, 0, 0),
                    radius=1,
                    resolution=(20, 20),
                    u_range=[0.001, PI - 0.001],
                    v_range=[0, TAU]
                )
                sphere1.set_color(RED)
                self.add(sphere1)
                sphere2 = Sphere(center=(-1, -3, 0), radius=2, resolution=(18, 18))
                sphere2.set_color(GREEN)
                self.add(sphere2)
                sphere3 = Sphere(center=(-1, 2, 0), radius=2, resolution=(16, 16))
                sphere3.set_color(BLUE)
                self.add(sphere3)
    rL   Nr   centerr-   radiusr4   rS   int | Sequence[int] | NonerP   rQ   rR   r;   r   r_   r`   c                $   t           j        t          j        k    rd}n,t           j        t          j        k    rd}nt          d          ||n|}|| _         t                      j        | j	        f|||d| | 
                    |           d S )N)e   3   )      zUnknown rendererrS   rP   rR   )r   r   r   r   r   	Exceptionr   r>   r?   rN   shift)	r@   r   r   rS   rP   rR   r;   	res_valuerA   s	           rB   r?   zSphere.__init__  s     ?l111!II_ 222 II.///#-#9ZZy
I	
!		
 	

 	
 	
 	
 	

6rC   ro   rp   r,   c                   | j         t          j        t          j        |          t          j        |          z  t          j        |          t          j        |          z  t          j        |           g          z  S )zThe z values defining the :class:`Sphere` being plotted.

        Returns
        -------
        :class:`Point3D`
            The z values defining the :class:`Sphere`.
        r   rx   arraycossinrt   s      rB   rN   zSphere.func  s_     {RXVAYY"BF1IIq		$9BF1II:F
 
 
 	
rC   )r   r-   r   r4   rS   r   rP   rQ   rR   rQ   r;   r   r_   r`   ro   r4   rp   r4   r_   r,   )
rD   rE   rF   r   ORIGINTAUPIr?   rN   rH   rI   s   @rB   r   r   a  sz        ( (X %15()3x()2w      <

 

 

 

 

 

 

 

rC   r   c                  .     e Zd ZdZeeedfd fdZ xZS )r   a  A spherical dot.

    Parameters
    ----------
    point
        The location of the dot.
    radius
        The radius of the dot.
    color
        The color of the :class:`Dot3D`.
    resolution
        The number of samples taken of the :class:`Dot3D`. A tuple can be
        used to define different resolutions for ``u`` and ``v`` respectively.

    Examples
    --------

    .. manim:: Dot3DExample
        :save_last_frame:

        class Dot3DExample(ThreeDScene):
            def construct(self):
                self.set_camera_orientation(phi=75*DEGREES, theta=-45*DEGREES)

                axes = ThreeDAxes()
                dot_1 = Dot3D(point=axes.coords_to_point(0, 0, 1), color=RED)
                dot_2 = Dot3D(point=axes.coords_to_point(2, 0, 0), radius=0.1, color=BLUE)
                dot_3 = Dot3D(point=[0, 0, 0], radius=0.1, color=ORANGE)
                self.add(axes, dot_1, dot_2,dot_3)
    )   r   pointr,   r   r4   r   r&   rS   int | tuple[int, int] | Noner;   r   r_   r`   c                l     t                      j        d|||d| |                     |           d S )N)r   r   rS   r=   )r>   r?   r   )r@   r   r   r   rS   r;   rA   s         rB   r?   zDot3D.__init__  sC     	VfVVvVVVurC   )r   r,   r   r4   r   r&   rS   r   r;   r   r_   r`   )	rD   rE   rF   r   r   DEFAULT_DOT_RADIUSr$   r?   rH   rI   s   @rB   r   r     s[         B  *$)39	 	 	 	 	 	 	 	 	 	 	rC   r   c                  >     e Zd ZdZddedfd fdZddZddZ xZS )r   a  A three-dimensional cube.

    Parameters
    ----------
    side_length
        Length of each side of the :class:`Cube`.
    fill_opacity
        The opacity of the :class:`Cube`, from 0 being fully transparent to 1 being
        fully opaque. Defaults to 0.75.
    fill_color
        The color of the :class:`Cube`.
    stroke_width
        The width of the stroke surrounding each face of the :class:`Cube`.

    Examples
    --------

    .. manim:: CubeExample
        :save_last_frame:

        class CubeExample(ThreeDScene):
            def construct(self):
                self.set_camera_orientation(phi=75*DEGREES, theta=-45*DEGREES)

                axes = ThreeDAxes()
                cube = Cube(side_length=3, fill_opacity=0.7, fill_color=BLUE)
                self.add(cube)
    r   g      ?r   side_lengthr4   rX   rW   r&   r\   r;   r   r_   r`   c                P    || _          t                      j        d|||d| d S )N)rW   rX   r\   r=   )r   r>   r?   )r@   r   rX   rW   r\   r;   rA   s         rB   r?   zCube.__init__  sO     ' 	
!%%	
 	
 		
 	
 	
 	
 	
rC   c                z   t           t          t          t          t          t
          fD ]}t          | j        dt          j	                  }|
                                 |                    | j        t          z  dz             |                    t          |                     |                     |           dS )z'Creates the sides of the :class:`Cube`.T)r   r9   
joint_typeg       @N)INOUTLEFTRIGHTUPDOWNr   r   LineJointTypeBEVELflipr   apply_matrixr*   r   )r@   vectr   s      rB   generate_pointszCube.generate_points  s    T5"d2 
	 
	D , (.  D
 IIKKKJJt'#-3444k$//000HHTNNNN
	 
	rC   c                .    |                                   d S rs   )r   r@   s    rB   init_pointszCube.init_points  s    rC   )r   r4   rX   r4   rW   r&   r\   r4   r;   r   r_   r`   r   )	rD   rE   rF   r   r    r?   r   r   rH   rI   s   @rB   r   r     s         > ")-
 
 
 
 
 
 
           rC   r   c                  8     e Zd ZdZg dfd fd	Zd fd
Z xZS )r	   a  A right rectangular prism (or rectangular cuboid).
    Defined by the length of each side in ``[x, y, z]`` format.

    Parameters
    ----------
    dimensions
        Dimensions of the :class:`Prism` in ``[x, y, z]`` format.

    Examples
    --------

    .. manim:: ExamplePrism
        :save_last_frame:

        class ExamplePrism(ThreeDScene):
            def construct(self):
                self.set_camera_orientation(phi=60 * DEGREES, theta=150 * DEGREES)
                prismSmall = Prism(dimensions=[1, 2, 3]).rotate(PI / 2)
                prismLarge = Prism(dimensions=[1.5, 3, 4.5]).move_to([2, 0, 0])
                self.add(prismSmall, prismLarge)
    )   r   rL   
dimensionsr/   r;   r   r_   r`   c                H    || _          t                      j        di | d S )Nr=   )r   r>   r?   )r@   r   r;   rA   s      rB   r?   zPrism.__init__:  s/    
 %""6"""""rC   c                    t                                                       t          | j                  D ]\  }}|                     ||d           dS )z(Creates the sides of the :class:`Prism`.T)stretchN)r>   r   r   r   rescale_to_fit)r@   dimvaluerA   s      rB   r   zPrism.generate_pointsB  s^    !!!#DO44 	: 	:JCsD9999	: 	:rC   )r   r/   r;   r   r_   r`   r   )rD   rE   rF   r   r?   r   rH   rI   s   @rB   r	   r	   #  ss         0 $-99# # # # # # #: : : : : : : : : :rC   r	   c                  p     e Zd ZdZddeddefddfd! fdZd"dZd#dZd#dZ	d$dZ
d%dZd&dZd'd Z xZS )(r
   ae  A circular cone.
    Can be defined using 2 parameters: its height, and its base radius.
    The polar angle, theta, can be calculated using arctan(base_radius /
    height) The spherical radius, r, is calculated using the pythagorean
    theorem.

    Parameters
    ----------
    base_radius
        The base radius from which the cone tapers.
    height
        The height measured from the plane formed by the base_radius to
        the apex of the cone.
    direction
        The direction of the apex.
    show_base
        Whether to show the base plane or not.
    v_range
        The azimuthal angle to start and end at.
    u_min
        The radius at the apex.
    checkerboard_colors
        Show checkerboard grid texture on the cone.

    Examples
    --------
    .. manim:: ExampleCone
        :save_last_frame:

        class ExampleCone(ThreeDScene):
            def construct(self):
                axes = ThreeDAxes()
                cone = Cone(direction=X_AXIS+Y_AXIS+2*Z_AXIS, resolution=8)
                self.set_camera_orientation(phi=5*PI/11, theta=PI/9)
                self.add(axes, cone)
    rL   Fr   base_radiusr4   height	directionr/   	show_baser:   rR   rQ   u_minrY   rZ   r;   r   r_   r`   c           
     >   t          j        |          | _        t          t          j        ||z            z
  | _         t                      j        | j        f||t          j	        |dz  |dz  z             f|d| || _
        d| _        d| _        t          || j        | j        d          | _        | j                            |t$          z             |                     |           |r|                     | j                   |                                  d S )Nr   )rR   rP   rY   r   )r   r   rX   r\   )rx   r   r
  r   arctanthetar>   r?   rN   sqrt
new_height_current_theta_current_phir   rW   rX   base_circler   r   _set_start_and_end_attributesr   _rotate_to_direction)
r@   r  r	  r
  r  rR   r  rY   r;   rA   s
            rB   r?   zCone.__init__o  s1    ),,")K&$8999
I	
BGKNVQY$>??@ 3		
 	

 	
 	
 	
 !!/*	
 
 
 	v{+++**9555 	'HHT%&&&!!#####rC   ro   rp   r,   c                (   |}|}t          j        |t          j        | j                  z  t          j        |          z  |t          j        | j                  z  t          j        |          z  |t          j        | j                  z  g          S )a  Converts from spherical coordinates to cartesian.

        Parameters
        ----------
        u
            The radius.
        v
            The azimuthal angle.

        Returns
        -------
        :class:`numpy.array`
            Points defining the :class:`Cone`.
        )rx   r   r   r  r   )r@   ro   rp   rphis        rB   rN   z	Cone.func  s}     xBF4:&&&4BF4:&&&4BF4:&&&
 
 	
rC   c                4    | j                                         S rs   )start_point
get_centerr   s    rB   	get_startzCone.get_start  s    **,,,rC   c                4    | j                                         S rs   	end_pointr  r   s    rB   get_endzCone.get_end      ~((***rC   c                   | j         \  }}}t          j        |dz  |dz  z   |dz  z             }|dk    rt          j        ||z            nd}|dk    r8|dk    rd}nFt          j        t          j                  }|dk     r
|t          z  }nt          j        ||z            }|dk     r
|t          z  }|                     | j         t          t                     |                     | j         t          t                     |                     |t          t                     |                     |t          t                     || _        || _        d S Nr   r   )about_pointr
  rx   r  arccosr  infr   rotater  Z_AXISr   r  Y_AXISr@   xyzr  r  r  s          rB   r  zCone._rotate_to_direction  =   .1aGAqD1a4K!Q$&''$%EE	!a%   q66Avvi''q552IC)AE""Cq552IC 	T&&FCCCT((&fEEE 	E6v666CV444 $rC   c                `    t          j        |          | _        |                                  dS )zChanges the direction of the apex of the :class:`Cone`.

        Parameters
        ----------
        direction
            The direction of the apex.
        N)rx   r   r
  r  r@   r
  s     rB   set_directionzCone.set_direction  s-     ),,!!#####rC   r.   c                    | j         S )zReturns the current direction of the apex of the :class:`Cone`.

        Returns
        -------
        direction : :class:`numpy.array`
            The direction of the apex.
        r
  r   s    rB   get_directionzCone.get_direction       ~rC   c                &   |t           j                            |          z  }| j                                        }||| j        z  z   }t          |          | _        t          |          | _        | 	                    | j        | j                   d S rs   )
rx   linalgnormr  r  r  r   r  r   r   )r@   r
  normalized_directionr   ends        rB   r  z"Cone._set_start_and_end_attributes  s    (29>>)+D+DD ++--*T_<<*511(--!4>22222rC   )r  r4   r	  r4   r
  r/   r  r:   rR   rQ   r  r4   rY   rZ   r;   r   r_   r`   r   r_   r,   r   r
  r/   r_   r`   )r_   r.   )r
  r.   r_   r`   )rD   rE   rF   r   r*  r   r?   rN   r  r!  r  r3  r6  r  rH   rI   s   @rB   r
   r
   I  s        # #N "(()3xMR$$ $$ $$ $$ $$ $$ $$L
 
 
 
2- - - -+ + + +       <	$ 	$ 	$ 	$   3 3 3 3 3 3 3 3rC   r
   c                  ^     e Zd ZdZddedefddfd fdZd dZd!dZd!dZ	d"dZ
d#dZ xZS )$r   a  A cylinder, defined by its height, radius and direction,

    Parameters
    ----------
    radius
        The radius of the cylinder.
    height
        The height of the cylinder.
    direction
        The direction of the central axis of the cylinder.
    v_range
        The height along the height axis (given by direction) to start and end on.
    show_ends
        Whether to show the end caps or not.
    resolution
        The number of samples taken of the :class:`Cylinder`. A tuple can be used
        to define different resolutions for ``u`` and ``v`` respectively.

    Examples
    --------
    .. manim:: ExampleCylinder
        :save_last_frame:

        class ExampleCylinder(ThreeDScene):
            def construct(self):
                axes = ThreeDAxes()
                cylinder = Cylinder(radius=2, height=3)
                self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
                self.add(axes, cylinder)
    rL   r   r   Tr   r   r   r4   r	  r
  r/   rR   rQ   	show_endsr:   rS   int | tuple[int, int]r;   r   r_   r`   c                   || _         || _         t                      j        | j        f|| j          dz  | j         dz  f|d| |r|                                  d| _        d| _        |                     |           d S )Nr   r   r   )	_heightr   r>   r?   rN   	add_basesr  r  r3  )	r@   r   r	  r
  rR   rA  rS   r;   rA   s	           rB   r?   zCylinder.__init__  s     I	
!l]Q&q(89		
 	

 	
 	
 	
  	NN9%%%%%rC   ro   rp   rq   c                    |}|}| j         }t          j        |t          j        |          z  |t          j        |          z  |g          S )a#  Converts from cylindrical coordinates to cartesian.

        Parameters
        ----------
        u
            The height.
        v
            The azimuthal angle.

        Returns
        -------
        :class:`numpy.ndarray`
            Points defining the :class:`Cylinder`.
        r   )r@   ro   rp   r	  r  r  s         rB   rN   zCylinder.func*  sD     KxRVC[[!bfSkk/6BCCCrC   c                B   t           j        t          j        k    r&t	          | t
                    sJ | j        }| j        }n(t           j        t          j        k    r| j	        }| j
        }t          | j        ||dd          | _        | j                            | j        d         t           z             t          | j        ||dd          | _        | j                            | j        d         t           z             |                     | j        | j                   dS )z"Adds the end caps of the cylinder.Tr   )r   r   rX   r9   r\   rL   N)r   r   r   r   rw   r   r   r   r   rW   rX   r   r   base_topr   rP   r   base_bottomr   )r@   r   r   s      rB   rE  zCylinder.add_bases>  s    ?l111dM22222JElGG_ 222OE'G; 
 
 
 	DLOb0111!; 
 
 
 	t|A3444 011111rC   c                   | j         \  }}}t          j        |dz  |dz  z   |dz  z             }|dk    rt          j        ||z            nd}|dk    r8|dk    rd}nFt          j        t          j                  }|dk     r
|t          z  }nt          j        ||z            }|dk     r
|t          z  }|                     | j         t          t                     |                     | j         t          t                     |                     |t          t                     |                     |t          t                     || _        || _        d S r$  r&  r,  s          rB   r  zCylinder._rotate_to_direction[  r0  rC   c                <    || _         |                                  dS )zSets the direction of the central axis of the :class:`Cylinder`.

        Parameters
        ----------
        direction : :class:`numpy.array`
            The direction of the central axis of the :class:`Cylinder`.
        N)r
  r  r2  s     rB   r3  zCylinder.set_directiony  s#     #!!#####rC   c                    | j         S )zReturns the direction of the central axis of the :class:`Cylinder`.

        Returns
        -------
        direction : :class:`numpy.array`
            The direction of the central axis of the :class:`Cylinder`.
        r5  r   s    rB   r6  zCylinder.get_direction  r7  rC   )r   r4   r	  r4   r
  r/   rR   rQ   rA  r:   rS   rB  r;   r   r_   r`   r   r   r>  r_   rq   )rD   rE   rF   r   r*  r   r?   rN   rE  r  r3  r6  rH   rI   s   @rB   r   r     s         B "(()3x,4& & & & & & &2D D D D(2 2 2 2:       <$ $ $ $       rC   r   c                       e Zd ZdZeedddfd"dZd# fdZ	 d$d%dZd&dZ	d&dZ
eedfd'd             Zeedfd'd!            Z xZS )(r   a  A cylindrical line, for use in ThreeDScene.

    Parameters
    ----------
    start
        The start point of the line.
    end
        The end point of the line.
    thickness
        The thickness of the line.
    color
        The color of the line.
    resolution
        The resolution of the line.
        By default this value is the number of points the line will sampled at.
        If you want the line to also come out checkered, use a tuple.
        For example, for a line made of 24 points with 4 checker points on each
        cylinder, pass the tuple (4, 24).

    Examples
    --------
    .. manim:: ExampleLine3D
        :save_last_frame:

        class ExampleLine3D(ThreeDScene):
            def construct(self):
                axes = ThreeDAxes()
                line = Line3D(start=np.array([0, 0, 0]), end=np.array([2, 2, 2]))
                self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
                self.add(axes, line)
    {Gz?Nr   r   r-   r<  	thicknessr4   r   ParsableManimColor | NonerS   rB  r;   r   c                $   || _         t          |t                    rd|fn|| _        t	          j        |t          j                  }t	          j        |t          j                  } | j        ||fi | ||                     |           d S d S )Nr   dtype)	rP  rw   r1   rS   rx   r   float64set_start_and_end_attrsr   )r@   r   r<  rP  r   rS   r;   s          rB   r?   zLine3D.__init__  s     #)*c::JQ
OO
 	 bj111hs"*---$$UC::6:::NN5!!!!! rC   r_   r`   c                ^   |                      |          }|                      |          }||z
  | _        t          j                            | j                  | _        t          | j                  | _        |                      || j                  | _        |                      || j                   | _	         t                      j        dt          j                            | j                  | j        | j        | j        d| |                     | j        | j	        z   dz             dS )a>  Sets the start and end points of the line.

        If either ``start`` or ``end`` are :class:`Mobjects <.Mobject>`,
        this gives their centers.

        Parameters
        ----------
        start
            Starting point or :class:`Mobject`.
        end
            Ending point or :class:`Mobject`.
        )r	  r   r
  rS   r   Nr=   )pointifyr   rx   r9  r:  lengthr(   r
  r   r<  r>   r?   rP  rS   r   )r@   r   r<  r;   rough_start	rough_endrA   s         rB   rV  zLine3D.set_start_and_end_attrs  s    mmE**MM#&&	+	innTY//#,TY#7#7 ]]5$.99
==t~o66 	
9>>$),,>n		
 	

 	
 	
 	
 	

DJ)Q./////rC   mob_or_pointMobject | Point3DLiker
  Vector3DLike | Noner,   c                    t          |t          t          f          r-|}||                                S |                    |          S t          j        |          S )a  Gets a point representing the center of the :class:`Mobjects <.Mobject>`.

        Parameters
        ----------
        mob_or_point
            :class:`Mobjects <.Mobject>` or point whose center should be returned.
        direction
            If an edge of a :class:`Mobjects <.Mobject>` should be returned, the direction of the edge.

        Returns
        -------
        :class:`numpy.array`
            Center of the :class:`Mobjects <.Mobject>` or point, or edge if direction is given.
        )rw   Mobjectr   r  get_boundary_pointrx   r   )r@   r\  r
  r   s       rB   rX  zLine3D.pointify  sZ    & lWm$<== 	9C ~~'''--i888x%%%rC   c                    | j         S )zReturns the starting point of the :class:`Line3D`.

        Returns
        -------
        start : :class:`numpy.array`
            Starting point of the :class:`Line3D`.
        )r   r   s    rB   r  zLine3D.get_start  s     zrC   c                    | j         S )zReturns the ending point of the :class:`Line3D`.

        Returns
        -------
        end : :class:`numpy.array`
            Ending point of the :class:`Line3D`.
        )r<  r   s    rB   r!  zLine3D.get_end  s     xrC      liner   rY  c                    t          j        |          }t          |j                  } | |||z  dz  z   |||z  dz  z
  fi |S )a  Returns a line parallel to another line going through
        a given point.

        Parameters
        ----------
        line
            The line to be parallel to.
        point
            The point to pass through.
        length
            Length of the parallel line.
        kwargs
            Additional parameters to be passed to the class.

        Returns
        -------
        :class:`Line3D`
            Line parallel to ``line``.

        Examples
        --------
        .. manim:: ParallelLineExample
            :save_last_frame:

            class ParallelLineExample(ThreeDScene):
                def construct(self):
                    self.set_camera_orientation(PI / 3, -PI / 4)
                    ax = ThreeDAxes((-5, 5), (-5, 5), (-5, 5), 10, 10, 10)
                    line1 = Line3D(RIGHT * 2, UP + OUT, color=RED)
                    line2 = Line3D.parallel_to(line1, color=YELLOW)
                    self.add(ax, line1, line2)
        r   )rx   asarrayr(   r   )clsre  r   rY  r;   np_pointr   s          rB   parallel_tozLine3D.parallel_to  sh    P :e$$##stf}q((tf}q((
 
 
 
 	
rC   c                   t          j        |          }t          j        |j        ||j        z
            }t          t           j                            |          t          j        d          k              rt          d          t          |j        |j        g|          \  }}t          ||z
            }	 | ||	|z  dz  z   ||	|z  dz  z
  fi |S )a  Returns a line perpendicular to another line going through
        a given point.

        Parameters
        ----------
        line
            The line to be perpendicular to.
        point
            The point to pass through.
        length
            Length of the perpendicular line.
        kwargs
            Additional parameters to be passed to the class.

        Returns
        -------
        :class:`Line3D`
            Line perpendicular to ``line``.

        Examples
        --------
        .. manim:: PerpLineExample
            :save_last_frame:

            class PerpLineExample(ThreeDScene):
                def construct(self):
                    self.set_camera_orientation(PI / 3, -PI / 4)
                    ax = ThreeDAxes((-5, 5), (-5, 5), (-5, 5), 10, 10, 10)
                    line1 = Line3D(RIGHT * 2, UP + OUT, color=RED)
                    line2 = Line3D.perpendicular_to(line1, color=BLUE)
                    self.add(ax, line1, line2)
        r   z!Could not find the perpendicular.r   )rx   rg  crossr   r   allr9  r:  zerosr   r)   r<  r(   )
rh  re  r   rY  r;   ri  r:  r   r<  r   s
             rB   perpendicular_tozLine3D.perpendicular_toH  s    P :e$$x	8dj#899ry~~d##rx{{233 	B@AAA+TZ,BDII
su%%stf}q((tf}q((
 
 
 
 	
rC   )r   r-   r<  r-   rP  r4   r   rQ  rS   rB  r;   r   )r   r-   r<  r-   r;   r   r_   r`   rs   )r\  r]  r
  r^  r_   r,   r=  )
re  r   r   r-   rY  r4   r;   r   r_   r   )rD   rE   rF   r   r   r   r?   rV  rX  r  r!  classmethodr   rj  ro  rH   rI   s   @rB   r   r     s        D " +/,." " " " "* 0  0  0  0  0  0J *.& & & & &6        $	-
 -
 -
 -
 [-
^  $	3
 3
 3
 3
 [3
 3
 3
 3
 3
rC   r   c                  <     e Zd ZdZeedddedfd fdZddZ xZ	S )r   a  An arrow made out of a cylindrical line and a conical tip.

    Parameters
    ----------
    start
        The start position of the arrow.
    end
        The end position of the arrow.
    thickness
        The thickness of the arrow.
    height
        The height of the conical tip.
    base_radius
        The base radius of the conical tip.
    color
        The color of the arrow.
    resolution
        The resolution of the arrow line.

    Examples
    --------
    .. manim:: ExampleArrow3D
        :save_last_frame:

        class ExampleArrow3D(ThreeDScene):
            def construct(self):
                axes = ThreeDAxes()
                arrow = Arrow3D(
                    start=np.array([0, 0, 0]),
                    end=np.array([2, 2, 2]),
                    resolution=8
                )
                self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
                self.add(axes, arrow)
    rO  g333333?g{Gz?r   r   r-   r<  rP  r4   r	  r  r   r&   rS   rB  r;   r   r_   r`   c           	         t                      j        d|||||d| t          j                            | j                  | _         | j        | j        | j	        || j
        z  z
  fi | t          d| j
        ||d|| _        t          j        |t          j                  }	| j                            |	           t!          |	          | _        |                     | j        | j                   |                     |           d S )N)r   r<  rP  r   rS   )r
  r  r	  rS  r=   )r>   r?   rx   r9  r:  r   rY  rV  r   r<  r
  r
   conerg  rU  r   r   r   r   r   )r@   r   r<  rP  r	  r  r   rS   r;   np_endrA   s             rB   r?   zArrow3D.__init__  s5    	 	
!	
 	
 	
 	
 	
 innTY//$$JHv..	
 	
 	
 	
 	

  
n#
 
 	
 
	 Crz222	(00+++urC   rq   c                4    | j                                         S rs   r  r   s    rB   r!  zArrow3D.get_end  r"  rC   )r   r-   r<  r-   rP  r4   r	  r4   r  r4   r   r&   rS   rB  r;   r   r_   r`   rM  )
rD   rE   rF   r   r   r   r$   r?   r!  rH   rI   s   @rB   r   r     sy        " "L " !$),.$ $ $ $ $ $ $L+ + + + + + + +rC   r   c                  @     e Zd ZdZdddefdefdfd fdZddZ xZS )r   aF  A torus.

    Parameters
    ----------
    major_radius
        Distance from the center of the tube to the center of the torus.
    minor_radius
        Radius of the tube.
    u_range
        The range of the ``u`` variable: ``(u_min, u_max)``.
    v_range
        The range of the ``v`` variable: ``(v_min, v_max)``.
    resolution
        The number of samples taken of the :class:`Torus`. A tuple can be
        used to define different resolutions for ``u`` and ``v`` respectively.

    Examples
    --------
    .. manim :: ExampleTorus
        :save_last_frame:

        class ExampleTorus(ThreeDScene):
            def construct(self):
                axes = ThreeDAxes()
                torus = Torus()
                self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
                self.add(axes, torus)
    r   rL   r   Nmajor_radiusr4   minor_radiusrP   rQ   rR   rS   r   r;   r   r_   r`   c                    t           j        t          j        k    rd}nt           j        t          j        k    rd}||n|}|| _        || _         t                      j        | j	        f|||d| d S )N)r   r   r@  )rP   rR   rS   )
r   r   r   r   r   Rr  r>   r?   rN   )	r@   rw  rx  rP   rR   rS   r;   r   rA   s	           rB   r?   zTorus.__init__  s     ?l111"II_ 222 I#-#9ZZy
I	
!		
 	

 	
 	
 	
 	
 	
rC   ro   rp   r,   c                   t          j        t          j        |          t          j        |          dg          }| j        | j        t          j        |          z  z
  |z  | j        t          j        |          z  t          z  z
  S )zThe z values defining the :class:`Torus` being plotted.

        Returns
        -------
        :class:`numpy.ndarray`
            The z values defining the :class:`Torus`.
        r   )rx   r   r   r   rz  r  r   )r@   ro   rp   Ps       rB   rN   z
Torus.func  sd     HbfQiiA.//"&))++q046BF1II3E3KKKrC   )rw  r4   rx  r4   rP   rQ   rR   rQ   rS   r   r;   r   r_   r`   r   )rD   rE   rF   r   r   r?   rN   rH   rI   s   @rB   r   r     s         >  ()3x()3x37
 
 
 
 
 
 
4	L 	L 	L 	L 	L 	L 	L 	LrC   r   )?r   
__future__r   __all__collections.abcr   r   r   typingr   r   r   r   numpyrx   manimr   r   manim.constantsmanim.mobject.geometry.arcr   manim.mobject.geometry.polygramr   manim.mobject.mobject)manim.mobject.opengl.opengl_compatibilityr   #manim.mobject.opengl.opengl_mobjectr   &manim.mobject.types.vectorized_mobjectr   r   r   manim.utils.colorr    r!   r"   r#   r$   r%   r&   r'   manim.utils.space_opsr(   r)   r*   )manim.mobject.graphing.coordinate_systemsr+   manim.typingr,   r-   r.   r/   r   r   r   r   r   r	   r
   r   r   r   r   r=   rC   rB   <module>r     s   ! ! " " " " " "   9 8 8 8 8 8 8 8 8 8 4 4 4 4 4 4 4 4 4 4 4 4                         - - - - - - 2 2 2 2 2 2 # # # # E E E E E E = = = = = = T T T T T T T T T T	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 Q P P P P P P P P P JDDDDDDIIIIIIIIIIII	< 	< 	< 	< 	<X 	< 	< 	< 	<^ ^ ^ ^ ^f ^ ^ ^ ^H	S
 S
 S
 S
 S
W S
 S
 S
l) ) ) ) )F ) ) )X= = = = =6 = = =@#: #: #: #: #:D #: #: #:Le3 e3 e3 e3 e37 e3 e3 e3P] ] ] ] ]w ] ] ]@k
 k
 k
 k
 k
X k
 k
 k
\L+ L+ L+ L+ L+f L+ L+ L+^AL AL AL AL ALG AL AL AL AL ALrC   