
    \hV                     2   S r / SQrSSKJrJrJrJrJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJrJrJrJrJrJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"  SSK#J$r$  SSK%J&r&  S r'SS jr(S r)SS jr*S r+S r,SS jr-S S jr.S S jr/S r0S r1g)!z
**Contains**

* refraction_angle
* fresnel_coefficients
* deviation
* brewster_angle
* critical_angle
* lens_makers_formula
* mirror_formula
* lens_formula
* hyperfocal_distance
* transverse_magnification
)
refraction_angle	deviationfresnel_coefficientsbrewster_anglecritical_anglelens_makers_formulamirror_formulalens_formulahyperfocal_distancetransverse_magnification    )FloatIoopizoo)S)Symbolsympify)sqrt)acosasinatan2cossintan)Matrix)cancel)Limit)Ray3D)intersection)Plane)is_sequence   )Mediumc                 b    [        U [        5      (       a  U R                  nU$ [        U 5      nU$ )z?
Helper function that returns refractive index, given a medium
)
isinstancer%   refractive_indexr   )mediumns     R/var/www/auris/envauris/lib/python3.13/site-packages/sympy/physics/optics/utils.pyrefractive_index_of_mediumr,   ,   s3     &&!!## H FOH    Nc                    [        U5      n[        U5      n [        U 5      n [        X5      nUbc  Uc  Ub  [	        S5      eSUs=::  a  [
        S-  :  d  O  [	        S5      eU(       a  Xx:  a  [	        S5      e[        U[        U5      -  U-  5      $ Sn	Ub  Ub  [	        S5      e[        U [        5      (       dR  [        U 5      (       a  [        U 5      n
O8[        U [        5      (       a  [        U R                  5      n
O[        S	5      eU n
Uba  [        U[        5      (       d  [        S
5      e[        U [        5      (       a  Sn	UR                  U 5      S   n[        UR                  5      nO[        U[        5      (       d  [        U5      (       a  [        U5      nOy[        U[        5      (       aW  [        UR                  5      n[        U [        5      (       a,  [        X5      n[!        U5      S:X  a  [	        S5      eSn	US   nO[        S5      eUnXV-  n[#        [%        S U
 5       5      5      n[#        [%        S U 5       5      5      nX-  n
X-  nU
R'                  U5      * nSUS-  SUS-  -
  -  -
  nUR(                  (       a  [*        R,                  $ X-  UU-  [#        U5      -
  U-  -   nUU-  nU	(       d  U$ [        WUS9$ ! [         a    Sn GNf = f! [        [        4 a    Sn GNf = f)a  
This function calculates transmitted vector after refraction at planar
surface. ``medium1`` and ``medium2`` can be ``Medium`` or any sympifiable object.
If ``incident`` is a number then treated as angle of incidence (in radians)
in which case refraction angle is returned.

If ``incident`` is an object of `Ray3D`, `normal` also has to be an instance
of `Ray3D` in order to get the output as a `Ray3D`. Please note that if
plane of separation is not provided and normal is an instance of `Ray3D`,
``normal`` will be assumed to be intersecting incident ray at the plane of
separation. This will not be the case when `normal` is a `Matrix` or
any other sequence.
If ``incident`` is an instance of `Ray3D` and `plane` has not been provided
and ``normal`` is not `Ray3D`, output will be a `Matrix`.

Parameters
==========

incident : Matrix, Ray3D, sequence or a number
    Incident vector or angle of incidence
medium1 : sympy.physics.optics.medium.Medium or sympifiable
    Medium 1 or its refractive index
medium2 : sympy.physics.optics.medium.Medium or sympifiable
    Medium 2 or its refractive index
normal : Matrix, Ray3D, or sequence
    Normal vector
plane : Plane
    Plane of separation of the two media.

Returns
=======

Returns an angle of refraction or a refracted ray depending on inputs.

Examples
========

>>> from sympy.physics.optics import refraction_angle
>>> from sympy.geometry import Point3D, Ray3D, Plane
>>> from sympy.matrices import Matrix
>>> from sympy import symbols, pi
>>> n = Matrix([0, 0, 1])
>>> P = Plane(Point3D(0, 0, 0), normal_vector=[0, 0, 1])
>>> r1 = Ray3D(Point3D(-1, -1, 1), Point3D(0, 0, 0))
>>> refraction_angle(r1, 1, 1, n)
Matrix([
[ 1],
[ 1],
[-1]])
>>> refraction_angle(r1, 1, 1, plane=P)
Ray3D(Point3D(0, 0, 0), Point3D(1, 1, -1))

With different index of refraction of the two media

>>> n1, n2 = symbols('n1, n2')
>>> refraction_angle(r1, n1, n2, n)
Matrix([
[                                n1/n2],
[                                n1/n2],
[-sqrt(3)*sqrt(-2*n1**2/(3*n2**2) + 1)]])
>>> refraction_angle(r1, n1, n2, plane=P)
Ray3D(Point3D(0, 0, 0), Point3D(n1/n2, n1/n2, -sqrt(3)*sqrt(-2*n1**2/(3*n2**2) + 1)))
>>> round(refraction_angle(pi/6, 1.2, 1.5), 5)
0.41152
Nz0Normal/plane not allowed if incident is an angleg        g      ?(Angle of incidence not in range [0:pi/2)z'Ray undergoes total internal reflectionFz%Either plane or normal is acceptable./incident should be a Matrix, Ray3D, or sequencez3plane should be an instance of geometry.plane.PlaneTr   z.Normal isn't concurrent with the incident ray.z-Normal should be a Matrix, Ray3D, or sequencec              3   *   #    U  H	  oS -  v   M     g7f   N .0is     r+   	<genexpr>#refraction_angle.<locals>.<genexpr>   s     4)QqD)   c              3   *   #    U  H	  oS -  v   M     g7fr2   r4   r5   s     r+   r8   r9      s     01Q$r:   r$   r3   )direction_ratio)r,   float	TypeErrorr   
ValueErrorr   r   r   r'   r   r#   r    r<   r"   r!   normal_vectorlenr   sumdotis_negativer   Zero)incidentmedium1medium2normalplanen1n2angle_of_incidencecritical_angle_
return_ray	_incidentintersection_pt_normaletamag_incident
mag_normalc1cs2drss                      r+   r   r   7   s   F 
$G	,B	#G	,B""8_(: %!2OPP(12c61GHH1CFGGBs-..r122 JV/@AAh''x  x(I%((x778IAC C 	 %''QRR h&&J#00:1=O,,-&&))6"" .FE** !7!78h..&28&DO?+q0(LN N &*
*9!*<CE E G
%C4)445Lc0001J IG
--
 	 B
c1fa"a%i 
 C
vv
-3r6DI-w6
6C
l
C
_c::o  "!"
 	" s"   K K) K&%K&)K?>K?c           
         SSU -  s=::  a
  [         :  d  O  [        S5      e[        U5      n[        U5      n[        U[	        U 5      -  U-  5      n [        X45      nUb  X`:  a  [	        X-
  5      * [	        X-   5      -  n[        X-
  5      [        X-   5      -  nS[	        U5      -  [        U 5      -  [	        X-   5      -  n	S[	        U5      -  [        U 5      -  [	        X-   5      [        X-
  5      -  -  n
XX/$ XC-  n[        [        U 5      [        [        [	        U 5      S-  US-  -
  5      -  -
  [        U 5      [        [        [	        U 5      S-  US-  -
  5      -  -   -  5      n[        US-  [        U 5      -  [        [        [	        U 5      S-  US-  -
  5      -  -
  US-  [        U 5      -  [        [        [	        U 5      S-  US-  -
  5      -  -   -  5      nX/$ ! [         a    Sn GNf = f)a  
This function uses Fresnel equations to calculate reflection and
transmission coefficients. Those are obtained for both polarisations
when the electric field vector is in the plane of incidence (labelled 'p')
and when the electric field vector is perpendicular to the plane of
incidence (labelled 's'). There are four real coefficients unless the
incident ray reflects in total internal in which case there are two complex
ones. Angle of incidence is the angle between the incident ray and the
surface normal. ``medium1`` and ``medium2`` can be ``Medium`` or any
sympifiable object.

Parameters
==========

angle_of_incidence : sympifiable

medium1 : Medium or sympifiable
    Medium 1 or its refractive index

medium2 : Medium or sympifiable
    Medium 2 or its refractive index

Returns
=======

Returns a list with four real Fresnel coefficients:
[reflection p (TM), reflection s (TE),
transmission p (TM), transmission s (TE)]
If the ray is undergoes total internal reflection then returns a
list of two complex Fresnel coefficients:
[reflection p (TM), reflection s (TE)]

Examples
========

>>> from sympy.physics.optics import fresnel_coefficients
>>> fresnel_coefficients(0.3, 1, 2)
[0.317843553417859, -0.348645229818821,
        0.658921776708929, 0.651354770181179]
>>> fresnel_coefficients(0.6, 2, 1)
[-0.235625382192159 - 0.971843958291041*I,
         0.816477005968898 - 0.577377951366403*I]

References
==========

.. [1] https://en.wikipedia.org/wiki/Fresnel_equations
r   r3   r/   N)r   r?   r,   r   r   r   r   r   r   r   r   )rM   rG   rH   rK   rL   angle_of_refraction(angle_of_total_internal_reflection_onsetR_sR_pT_sT_pr*   s               r+   r   r      s=   b $$)r)CDD	#G	,B	#G	,Br#&8"99"<=83A"3I0 07,A%;<<'=>?$:;'=>?'((-?)@@'=>?'((-?)@@(>?'=>?@ ###Ec,-$s-.1AqD899:()$s-.1AqD899:; < ad3122$s-.1AqD899:Q$s-..$s-.1AqD899:; < z3  83708s   G& &G65G6c                    [        U UUUUS9n [        U 5      nUb  [        U5      U-
  $ US:w  Ga  [	        U[
        5      (       a  [        UR                  5      n[	        U [        5      (       dR  [        U 5      (       a  [        U 5      nO8[	        U [
        5      (       a  [        U R                  5      nO[        S5      eU nUcj  [	        U[        5      (       dR  [        U5      (       a  [        U5      nON[	        U[
        5      (       a  [        UR                  5      nO#[        S5      eUnO[        UR                  5      n[        [        S U 5       5      5      n	[        [        S U 5       5      5      n
[        [        S U 5       5      5      nXy-  nX-  nX[-  n[        UR                  U5      5      n[        UR                  U5      5      nX-
  $ g! [         a    Sn GNf = f)	aG  
This function calculates the angle of deviation of a ray
due to refraction at planar surface.

Parameters
==========

incident : Matrix, Ray3D, sequence or float
    Incident vector or angle of incidence
medium1 : sympy.physics.optics.medium.Medium or sympifiable
    Medium 1 or its refractive index
medium2 : sympy.physics.optics.medium.Medium or sympifiable
    Medium 2 or its refractive index
normal : Matrix, Ray3D, or sequence
    Normal vector
plane : Plane
    Plane of separation of the two media.

Returns angular deviation between incident and refracted rays

Examples
========

>>> from sympy.physics.optics import deviation
>>> from sympy.geometry import Point3D, Ray3D, Plane
>>> from sympy.matrices import Matrix
>>> from sympy import symbols
>>> n1, n2 = symbols('n1, n2')
>>> n = Matrix([0, 0, 1])
>>> P = Plane(Point3D(0, 0, 0), normal_vector=[0, 0, 1])
>>> r1 = Ray3D(Point3D(-1, -1, 1), Point3D(0, 0, 0))
>>> deviation(r1, 1, 1, n)
0
>>> deviation(r1, n1, n2, plane=P)
-acos(-sqrt(-2*n1**2/(3*n2**2) + 1)) + acos(-sqrt(3)/3)
>>> round(deviation(0.1, 1.2, 1.5), 5)
-0.02005
)rI   rJ   Nr   r0   z-normal should be a Matrix, Ray3D, or sequencec              3   *   #    U  H	  oS -  v   M     g7fr2   r4   r5   s     r+   r8   deviation.<locals>.<genexpr>  s     8i1ir:   c              3   *   #    U  H	  oS -  v   M     g7fr2   r4   r5   s     r+   r8   rb     s     4GqdGr:   c              3   *   #    U  H	  oS -  v   M     g7fr2   r4   r5   s     r+   r8   rb     s      9y!Ayr:   )r   r   r>   r=   r'   r    r   r<   r#   r@   r   rB   r   rC   )rF   rG   rH   rI   rJ   	refractedrM   rP   rR   rT   rU   mag_refractedr7   rs                 r+   r   r   0  s   N !!(!((.',	.I
""8_ %Y"444A~i''y889I(F++8$$"8,	He,,"8#;#;<	EG G !I=ff--v&&$VnG..$V%;%;<G#GI I !U001GC8i889#4G445
S 9y 99:!	"	w'(w'(uK   "!"s   G G-,G-c                 D    [        U 5      n[        U5      n[        X25      $ )au  
This function calculates the Brewster's angle of incidence to Medium 2 from
Medium 1 in radians.

Parameters
==========

medium 1 : Medium or sympifiable
    Refractive index of Medium 1
medium 2 : Medium or sympifiable
    Refractive index of Medium 1

Examples
========

>>> from sympy.physics.optics import brewster_angle
>>> brewster_angle(1, 1.33)
0.926093295503462

)r,   r   rG   rH   rK   rL   s       r+   r   r     s"    , 
$G	,B	#G	,B=r-   c                 h    [        U 5      n[        U5      nX2:  a  [        S5      e[        X2-  5      $ )a  
This function calculates the critical angle of incidence (marking the onset
of total internal) to Medium 2 from Medium 1 in radians.

Parameters
==========

medium 1 : Medium or sympifiable
    Refractive index of Medium 1.
medium 2 : Medium or sympifiable
    Refractive index of Medium 1.

Examples
========

>>> from sympy.physics.optics import critical_angle
>>> critical_angle(1.33, 1)
0.850908514477849

z0Total internal reflection impossible for n1 < n2)r,   r?   r   ri   s       r+   r   r     s5    , 
$G	,B	#G	,B	wKLLBE{r-   c                 P   [        U [        5      (       a  U R                  n O[        U 5      n [        U[        5      (       a  UR                  nO[        U5      n[        U5      nSX-
  U-  SU-  SU-  -
  X-
  U-  X-  U-  -  -   -  -  nU[        :X  a  [
        R                  $ U$ )a  
This function calculates focal length of a lens.
It follows cartesian sign convention.

Parameters
==========

n_lens : Medium or sympifiable
    Index of refraction of lens.
n_surr : Medium or sympifiable
    Index of reflection of surrounding.
r1 : sympifiable
    Radius of curvature of first surface.
r2 : sympifiable
    Radius of curvature of second surface.
d : sympifiable, optional
    Thickness of lens, default value is 0.

Examples
========

>>> from sympy.physics.optics import lens_makers_formula
>>> from sympy import S
>>> lens_makers_formula(1.33, 1, 10, -10)
15.1515151515151
>>> lens_makers_formula(1.2, 1, 10, S.Infinity)
50.0000000000000
>>> lens_makers_formula(1.33, 1, 10, -10, d=1)
15.3418463277618

r$   )r'   r%   r(   r   r   r   Infinity)n_lensn_surrr1r2dfocal_lengths         r+   r   r     s    B &&!!((&&!!((
Av&0!B$2+6?VWBW\b\gjl\lAm2nopLszzr-   c                 6   U (       a  U(       a  U(       a  [        S5      e[        U 5      n [        U5      n[        U5      nU[        L a  [        S5      nU[        L a  [        S5      nU [        L a  [        S5      nU c  U[        L a?  U[        L a6  [	        [	        WW-  XC-   -  U[        5      U[        5      R                  5       $ U[        L a'  [	        UW-  X#-   -  U[        5      R                  5       $ U[        L a'  [	        WU-  XA-   -  U[        5      R                  5       $ X!-  X!-   -  $ Uc  U[        L a?  U [        L a6  [	        [	        WW-  XE-
  -  U[        5      U[        5      R                  5       $ U[        L a'  [	        WU -  X@-
  -  U[        5      R                  5       $ U [        L a'  [	        UW-  X%-
  -  U[        5      R                  5       $ X -  X -
  -  $ Uc  U[        L a?  U [        L a6  [	        [	        WW-  X5-
  -  U[        5      U[        5      R                  5       $ U[        L a'  [	        WU -  X0-
  -  U[        5      R                  5       $ U [        L a'  [	        UW-  X-
  -  U[        5      R                  5       $ X-  X-
  -  $ g)am  
This function provides one of the three parameters
when two of them are supplied.
This is valid only for paraxial rays.

Parameters
==========

focal_length : sympifiable
    Focal length of the mirror.
u : sympifiable
    Distance of object from the pole on
    the principal axis.
v : sympifiable
    Distance of the image from the pole
    on the principal axis.

Examples
========

>>> from sympy.physics.optics import mirror_formula
>>> from sympy.abc import f, u, v
>>> mirror_formula(focal_length=f, u=u)
f*u/(-f + u)
>>> mirror_formula(focal_length=f, v=v)
f*v/(-f + v)
>>> mirror_formula(u=u, v=v)
u*v/(u + v)

"Please provide only two parametersuvfNr?   r   r   r   r   doitrr   ru   rv   _u_v_fs         r+   r   r     sM   > a=>><(L
A
ABwC[BwC[rC[7qBwr"ubgB7R@EEGG72qvB/44667ArvB/4466sAE{y7|r)r"ubgB7R@EEGG7L"*;<b"EJJLL22qvB/4466~q/00y7|r)r"ubgB7R@EEGG7L"*;<b"EJJLL22qvB/4466~q/00 r-   c                 6   U (       a  U(       a  U(       a  [        S5      e[        U 5      n [        U5      n[        U5      nU[        L a  [        S5      nU[        L a  [        S5      nU [        L a  [        S5      nU c  U[        L a?  U[        L a6  [	        [	        WW-  X4-
  -  U[        5      U[        5      R                  5       $ U[        L a'  [	        UW-  X2-
  -  U[        5      R                  5       $ U[        L a'  [	        WU-  X-
  -  U[        5      R                  5       $ X!-  X-
  -  $ Uc  U[        L a?  U [        L a6  [	        [	        WW-  XT-
  -  U[        5      U[        5      R                  5       $ U[        L a'  [	        WU -  X-
  -  U[        5      R                  5       $ U [        L a'  [	        UW-  XR-
  -  U[        5      R                  5       $ X -  X-
  -  $ Uc  U[        L a?  U [        L a6  [	        [	        WW-  X5-   -  U[        5      U[        5      R                  5       $ U[        L a'  [	        WU -  X0-   -  U[        5      R                  5       $ U [        L a'  [	        UW-  X-   -  U[        5      R                  5       $ X-  X-   -  $ g)aw  
This function provides one of the three parameters
when two of them are supplied.
This is valid only for paraxial rays.

Parameters
==========

focal_length : sympifiable
    Focal length of the mirror.
u : sympifiable
    Distance of object from the optical center on
    the principal axis.
v : sympifiable
    Distance of the image from the optical center
    on the principal axis.

Examples
========

>>> from sympy.physics.optics import lens_formula
>>> from sympy.abc import f, u, v
>>> lens_formula(focal_length=f, u=u)
f*u/(f + u)
>>> lens_formula(focal_length=f, v=v)
f*v/(f - v)
>>> lens_formula(u=u, v=v)
u*v/(u - v)

rt   ru   rv   rw   Nrx   rz   s         r+   r	   r	   >  sM   > a=>><(L
A
ABwC[BwC[rC[7qBwr"ubgB7R@EEGG72rvB/44667AqvB/4466sAE{y7|r)r"ubgB7R@EEGG7L,*;<b"EJJLL22rvB/4466~|/00y7|r)r"ubgB7R@EEGG7L"*;<b"EJJLL22qvB/4466~q/00 r-   c                 ^    [        U 5      n [        U5      n[        U5      nSX-  -  U S-  -  $ )aM  

Parameters
==========

f: sympifiable
    Focal length of a given lens.

N: sympifiable
    F-number of a given lens.

c: sympifiable
    Circle of Confusion (CoC) of a given image format.

Example
=======

>>> from sympy.physics.optics import hyperfocal_distance
>>> round(hyperfocal_distance(f = 0.5, N = 8, c = 0.0033), 2)
9.47
r$   r3   r   )rw   Ncs      r+   r
   r
     s4    . 	
A
A
AquI1r-   c                 8    [        U 5      n [        U5      nX-  * $ )ae  

Calculates the transverse magnification upon reflection in a mirror,
which is the ratio of the image size to the object size.

Parameters
==========

so: sympifiable
    Lens-object distance.

si: sympifiable
    Lens-image distance.

Example
=======

>>> from sympy.physics.optics import transverse_magnification
>>> transverse_magnification(30, 15)
-2

r   )sisos     r+   r   r     s     0 
B	BeHr-   )NN)r   )NNN)2__doc____all__sympy.core.numbersr   r   r   r   r   sympy.core.singletonr   sympy.core.symbolr   sympy.core.sympifyr   (sympy.functions.elementary.miscellaneousr   (sympy.functions.elementary.trigonometricr   r   r   r   r   r   sympy.matrices.denser   sympy.polys.polytoolsr   sympy.series.limitsr   sympy.geometry.liner    sympy.geometry.utilr!   sympy.geometry.planer"   sympy.utilities.iterablesr#   r)   r%   r,   r   r   r   r   r   r   r   r	   r
   r   r4   r-   r+   <module>r      s   
 7 6 " $ & 9 W W ' ( % % , & 1 `;FSlYx6@/dB1JB1H:r-   