o
    8Vag%                     @   s   d Z dgZddlmZmZmZmZmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZmZmZ eee ZG dd deZdS )zb
This module has all the classes and functions related to waves in optics.

**Contains**

* TWave
TWave    )sympifypisincossqrtNumberSymbolSsymbols
Derivativeatan2)Expr)speed_of_lightmetersecondc                   @   s   e Zd ZdZdejdedfddZedd Z	edd	 Z
ed
d Zedd Zedd Zedd Zedd Zedd Zdd ZeZdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- ZdS ).r   a,  
    This is a simple transverse sine wave travelling in a one-dimensional space.
    Basic properties are required at the time of creation of the object,
    but they can be changed later with respective methods provided.

    Explanation
    ===========

    It is represented as :math:`A \times cos(k*x - \omega \times t + \phi )`,
    where :math:`A` is the amplitude, :math:`\omega` is the angular frequency,
    :math:`k` is the wavenumber (spatial frequency), :math:`x` is a spatial variable
    to represent the position on the dimension on which the wave propagates,
    and :math:`\phi` is the phase angle of the wave.


    Arguments
    =========

    amplitude : Sympifyable
        Amplitude of the wave.
    frequency : Sympifyable
        Frequency of the wave.
    phase : Sympifyable
        Phase angle of the wave.
    time_period : Sympifyable
        Time period of the wave.
    n : Sympifyable
        Refractive index of the medium.

    Raises
    =======

    ValueError : When neither frequency nor time period is provided
        or they are not consistent.
    TypeError : When anything other than TWave objects is added.


    Examples
    ========

    >>> from sympy import symbols
    >>> from sympy.physics.optics import TWave
    >>> A1, phi1, A2, phi2, f = symbols('A1, phi1, A2, phi2, f')
    >>> w1 = TWave(A1, f, phi1)
    >>> w2 = TWave(A2, f, phi2)
    >>> w3 = w1 + w2  # Superposition of two waves
    >>> w3
    TWave(sqrt(A1**2 + 2*A1*A2*cos(phi1 - phi2) + A2**2), f,
        atan2(A1*sin(phi1) + A2*sin(phi2), A1*cos(phi1) + A2*cos(phi2)))
    >>> w3.amplitude
    sqrt(A1**2 + 2*A1*A2*cos(phi1 - phi2) + A2**2)
    >>> w3.phase
    atan2(A1*sin(phi1) + A2*sin(phi2), A1*cos(phi1) + A2*cos(phi2))
    >>> w3.speed
    299792458*meter/(second*n)
    >>> w3.angular_velocity
    2*pi*f

    Nnc                 C   s   t |}t |}t |}t |}t |}|| _|| _|| _|| _|| _|d ur-d| j | _|d urEd| j | _|d urE|d| krEtd|d u rQ|d u rStdd S d S )N   z/frequency and time_period should be consistent.z*Either frequency or time period is needed.)r   
_frequency
_amplitude_phase_time_period_n
ValueError)self	amplitude	frequencyphasetime_periodr    r   </usr/lib/python3/dist-packages/sympy/physics/optics/waves.py__init__R   s(   zTWave.__init__c                 C      | j S )a?  
        Returns the frequency of the wave,
        in cycles per second.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.frequency
        f
        )r   r   r   r   r    r   m      zTWave.frequencyc                 C   r"   )aI  
        Returns the temporal period of the wave,
        in seconds per cycle.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.time_period
        1/f
        )r   r#   r   r   r    r      r$   zTWave.time_periodc                 C   s   t | j| j  S )a  
        Returns the wavelength (spatial period) of the wave,
        in meters per cycle.
        It depends on the medium of the wave.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.wavelength
        299792458*meter/(second*f*n)
        )cr   r   r#   r   r   r    
wavelength   s   zTWave.wavelengthc                 C   r"   )a!  
        Returns the amplitude of the wave.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.amplitude
        A
        )r   r#   r   r   r    r      s   zTWave.amplitudec                 C   r"   )a5  
        Returns the phase angle of the wave,
        in radians.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.phase
        phi
        )r   r#   r   r   r    r      r$   zTWave.phasec                 C   s   | j | j S )a  
        Returns the propagation speed of the wave,
        in meters per second.
        It is dependent on the propagation medium.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.speed
        299792458*meter/(second*n)
        )r&   r   r#   r   r   r    speed   s   zTWave.speedc                 C   s   dt  | j S )aS  
        Returns the angular velocity of the wave,
        in radians per second.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.angular_velocity
        2*pi*f
           )r   r   r#   r   r   r    angular_velocity      zTWave.angular_velocityc                 C   s   dt  | j S )a_  
        Returns the wavenumber of the wave,
        in radians per meter.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.wavenumber
        pi*second*f*n/(149896229*meter)
        r(   )r   r&   r#   r   r   r    
wavenumber   r*   zTWave.wavenumberc                 C   s    ddl m} t| j|| j S )z!String representation of a TWave.r   )sstr)Zsympy.printingr,   type__name__args)r   r,   r   r   r    __str__   s   zTWave.__str__c              	   C   s   t |trU| j|jkrQ| j|jkrQtt| jd |jd  d| j |j t| j|j   | jt	| jt
| j |jt
|j  | jt| j |jt|j  S tdtt|jd )z
        Addition of two waves will result in their superposition.
        The type of interference will depend on their phase angles.
        r(   zJInterference of waves with different frequencies has not been implemented.z" and TWave objects can't be added.)
isinstancer   r   r&   r   r   r   r   r   r   r   NotImplementedError	TypeErrorr-   r.   r   otherr   r   r    __add__  s,   


zTWave.__add__c                 C   sD   t |}t|trt| j| g| jdd R  S tt|jd )zT
        Multiplying a wave by a scalar rescales the amplitude of the wave.
        r   Nz' and TWave objects can't be multiplied.)	r   r1   r   r   r   r/   r3   r-   r.   r4   r   r   r    __mul__  s   
 zTWave.__mul__c                 C   s   |  d| S Nr6   r4   r   r   r    __sub__%  s   zTWave.__sub__c                 C   s
   |  dS r8   r7   r#   r   r   r    __neg__(     
zTWave.__neg__c                 C   
   |  |S Nr:   r4   r   r   r    __radd__+  r>   zTWave.__radd__c                 C   r?   r@   r<   r4   r   r   r    __rmul__.  r>   zTWave.__rmul__c                 C   s   |   |S r@   )rA   r4   r   r   r    __rsub__1  s   zTWave.__rsub__c                 O   s8   | j t| jtd | jtd  | j td  dd S )Nxtr(   F)Zevaluate)r   r   r+   r	   r)   r   r   r   r/   kwargsr   r   r    _eval_rewrite_as_sin4  s   zTWave._eval_rewrite_as_sinc                 O   s,   | j t| jtd | jtd  | j  S )NrD   rE   )r   r   r+   r	   r)   r   rF   r   r   r    _eval_rewrite_as_cos8  s
   zTWave._eval_rewrite_as_cosc           	      O   sP   ddl m} td\}}}}|d}t||||d|| t||||d  S )Nr   )Functionzmu, epsilon, x, tEr(   )sympyrJ   r   r   )	r   r/   rG   rJ   ZmuepsilonrD   rE   rK   r   r   r    _eval_rewrite_as_pde<  s   ,zTWave._eval_rewrite_as_pdec                 O   s@   ddl m}m} | j||| jtd | jtd  | j   S )Nr   )expIrD   rE   )rL   rO   rP   r   r+   r	   r)   r   )r   r/   rG   rO   rP   r   r   r    _eval_rewrite_as_expB  s   
zTWave._eval_rewrite_as_exp)r.   
__module____qualname____doc__r
   ZZeror	   r!   propertyr   r   r&   r   r   r'   r)   r+   r0   __repr__r6   r7   r;   r=   rA   rB   rC   rH   rI   rN   rQ   r   r   r   r    r      sH    ?









N)rT   __all__rL   r   r   r   r   r   r   r	   r
   r   r   r   Zsympy.core.exprr   Zsympy.physics.unitsr   r   r   Z
convert_tor%   r   r   r   r   r    <module>   s    4