K iQxdZgdZddlmZddlmZmZddlmZddl m Z m Z ddl m Z ddlmZdd lmZmZdd lmZdd lmZGd d eZGddeZGddeZGddeZGddeZGddeZGddeZGddeZGddeZd%dZ dZ!d Z"d!Z#e#Z$d"Z%d#Z&y$)&a Gaussian optics. The module implements: - Ray transfer matrices for geometrical and gaussian optics. See RayTransferMatrix, GeometricRay and BeamParameter - Conjugation relations for geometrical and gaussian optics. See geometric_conj*, gauss_conj and conjugate_gauss_beams The conventions for the distances are as follows: focal distance positive for convergent lenses object distance positive for real objects image distance positive for real images )RayTransferMatrix FreeSpaceFlatRefractionCurvedRefraction FlatMirror CurvedMirrorThinLens GeometricRay BeamParameterwaist2rayleighrayleigh2waistgeometric_conj_abgeometric_conj_afgeometric_conj_bf gaussian_conjconjugate_gauss_beams)Expr)Ipi)sympify)imre)sqrt)atan2)MatrixMutableDenseMatrix)together) filldedentc\eZdZdZdZdZedZedZedZ edZ y) ra Base class for a Ray Transfer Matrix. It should be used if there is not already a more specific subclass mentioned in See Also. Parameters ========== parameters : A, B, C and D or 2x2 matrix (Matrix(2, 2, [A, B, C, D])) Examples ======== >>> from sympy.physics.optics import RayTransferMatrix, ThinLens >>> from sympy import Symbol, Matrix >>> mat = RayTransferMatrix(1, 2, 3, 4) >>> mat Matrix([ [1, 2], [3, 4]]) >>> RayTransferMatrix(Matrix([[1, 2], [3, 4]])) Matrix([ [1, 2], [3, 4]]) >>> mat.A 1 >>> f = Symbol('f') >>> lens = ThinLens(f) >>> lens Matrix([ [ 1, 0], [-1/f, 1]]) >>> lens.C -1/f See Also ======== GeometricRay, BeamParameter, FreeSpace, FlatRefraction, CurvedRefraction, FlatMirror, CurvedMirror, ThinLens References ========== .. [1] https://en.wikipedia.org/wiki/Ray_transfer_matrix_analysis c&t|dk(r|d|df|d|dff}nYt|dk(r+t|dtr|djdk(r|d}n t t dt |ztj||S)Nr)r#r#z` Expecting 2x2 Matrix or the 4 elements of the Matrix but got %slen isinstancershape ValueErrorrstr__new__clsargstemps c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/physics/optics/gaussopt.pyr+zRayTransferMatrix.__new__ss t9>!Wd1g&a$q'(:;D Y!^47F+GMMV+7DZ))+.t9)567 7~~c4((c t|tr tt|t|zSt|tr tt|t|zSt|tr{t|t|j fdfz}|d|dz j d}t |jtt|tt|Stj||S)Nr"rr"T)complex)z_r) r'rrr r qexpandwavelenrrr__mul__)selfotherr/r6s r0r9zRayTransferMatrix.__mul__s e. /$VD\&-%?@ @ | ,t VE] :; ; } -$< D'9 ::Daa(((6A !)"Q%%-be_6 6>>$. .r1c |dS)z The A parameter of the Matrix. Examples ======== >>> from sympy.physics.optics import RayTransferMatrix >>> mat = RayTransferMatrix(1, 2, 3, 4) >>> mat.A 1 )rrr:s r0AzRayTransferMatrix.ADzr1c |dS)z The B parameter of the Matrix. Examples ======== >>> from sympy.physics.optics import RayTransferMatrix >>> mat = RayTransferMatrix(1, 2, 3, 4) >>> mat.B 2 )rr"r=r>s r0BzRayTransferMatrix.Br@r1c |dS)z The C parameter of the Matrix. Examples ======== >>> from sympy.physics.optics import RayTransferMatrix >>> mat = RayTransferMatrix(1, 2, 3, 4) >>> mat.C 3 )r"rr=r>s r0CzRayTransferMatrix.Cr@r1c |dS)z The D parameter of the Matrix. Examples ======== >>> from sympy.physics.optics import RayTransferMatrix >>> mat = RayTransferMatrix(1, 2, 3, 4) >>> mat.D 4 )r"r"r=r>s r0DzRayTransferMatrix.Dr@r1N) __name__ __module__ __qualname____doc__r+r9propertyr?rBrDrFr=r1r0rr;sb5n ) /        r1rceZdZdZdZy)raQ Ray Transfer Matrix for free space. Parameters ========== distance See Also ======== RayTransferMatrix Examples ======== >>> from sympy.physics.optics import FreeSpace >>> from sympy import symbols >>> d = symbols('d') >>> FreeSpace(d) Matrix([ [1, d], [0, 1]]) c4tj|d|ddSNr"rrr+)r-ds r0r+zFreeSpace.__new__ ((aAq99r1NrGrHrIrJr+r=r1r0rrs 0:r1rceZdZdZdZy)ra Ray Transfer Matrix for refraction. Parameters ========== n1 : Refractive index of one medium. n2 : Refractive index of other medium. See Also ======== RayTransferMatrix Examples ======== >>> from sympy.physics.optics import FlatRefraction >>> from sympy import symbols >>> n1, n2 = symbols('n1 n2') >>> FlatRefraction(n1, n2) Matrix([ [1, 0], [0, n1/n2]]) cdtt||f\}}tj|ddd||z SrNmaprrr+)r-n1n2s r0r+zFlatRefraction.__new__s3Wr2h'B ((aAr"u==r1NrRr=r1r0rrs 6>r1rceZdZdZdZy)raB Ray Transfer Matrix for refraction on curved interface. Parameters ========== R : Radius of curvature (positive for concave). n1 : Refractive index of one medium. n2 : Refractive index of other medium. See Also ======== RayTransferMatrix Examples ======== >>> from sympy.physics.optics import CurvedRefraction >>> from sympy import symbols >>> R, n1, n2 = symbols('R n1 n2') >>> CurvedRefraction(R, n1, n2) Matrix([ [ 1, 0], [(n1 - n2)/(R*n2), n1/n2]]) cztt|||f\}}}tj|dd||z |z |z ||z SrNrU)r-RrWrXs r0r+zCurvedRefraction.__new__(sC!R- 2r ((aR"WaKNBrEJJr1NrRr=r1r0rr s :Kr1rceZdZdZdZy)rz Ray Transfer Matrix for reflection. See Also ======== RayTransferMatrix Examples ======== >>> from sympy.physics.optics import FlatMirror >>> FlatMirror() Matrix([ [1, 0], [0, 1]]) c4tj|ddddSrNrO)r-s r0r+zFlatMirror.__new__?rQr1NrRr=r1r0rr-s ":r1rceZdZdZdZy)ra Ray Transfer Matrix for reflection from curved surface. Parameters ========== R : radius of curvature (positive for concave) See Also ======== RayTransferMatrix Examples ======== >>> from sympy.physics.optics import CurvedMirror >>> from sympy import symbols >>> R = symbols('R') >>> CurvedMirror(R) Matrix([ [ 1, 0], [-2/R, 1]]) cPt|}tj|ddd|z dS)Nr"rrrr+)r-r[s r0r+zCurvedMirror.__new__\( AJ ((aBqD!<>> from sympy.physics.optics import ThinLens >>> from sympy import symbols >>> f = symbols('f') >>> ThinLens(f) Matrix([ [ 1, 0], [-1/f, 1]]) cPt|}tj|ddd|z dS)Nr"rra)r-fs r0r+zThinLens.__new__{rbr1NrRr=r1r0rras 2=r1rc6eZdZdZdZedZedZy)r a Representation for a geometric ray in the Ray Transfer Matrix formalism. Parameters ========== h : height, and angle : angle, or matrix : a 2x1 matrix (Matrix(2, 1, [height, angle])) Examples ======== >>> from sympy.physics.optics import GeometricRay, FreeSpace >>> from sympy import symbols, Matrix >>> d, h, angle = symbols('d, h, angle') >>> GeometricRay(h, angle) Matrix([ [ h], [angle]]) >>> FreeSpace(d)*GeometricRay(h, angle) Matrix([ [angle*d + h], [ angle]]) >>> GeometricRay( Matrix( ((h,), (angle,)) ) ) Matrix([ [ h], [angle]]) See Also ======== RayTransferMatrix ct|dk(r+t|dtr|djdk(r|d}n;t|dk(r |df|dff}n t t dt |ztj||S)Nr"r)r#r"r#z` Expecting 2x1 Matrix or the 2 elements of the Matrix but got %sr%r,s r0r+zGeometricRay.__new__s t9>ja&9GMMV+7D Y!^!WJa +DZ))+.t9)567 7~~c4((r1c |dS)a0 The distance from the optical axis. Examples ======== >>> from sympy.physics.optics import GeometricRay >>> from sympy import symbols >>> h, angle = symbols('h, angle') >>> gRay = GeometricRay(h, angle) >>> gRay.height h rr=r>s r0heightzGeometricRay.height Awr1c |dS)a0 The angle with the optical axis. Examples ======== >>> from sympy.physics.optics import GeometricRay >>> from sympy import symbols >>> h, angle = symbols('h, angle') >>> gRay = GeometricRay(h, angle) >>> gRay.angle angle r"r=r>s r0anglezGeometricRay.anglerkr1N)rGrHrIrJr+rKrjrmr=r1r0r r s5%N ) r1r ceZdZdZddZedZedZedZedZ edZ ed Z ed Z ed Z ed Zed ZedZy)r a Representation for a gaussian ray in the Ray Transfer Matrix formalism. Parameters ========== wavelen : the wavelength, z : the distance to waist, and w : the waist, or z_r : the rayleigh range. n : the refractive index of medium. Examples ======== >>> from sympy.physics.optics import BeamParameter >>> p = BeamParameter(530e-9, 1, w=1e-3) >>> p.q 1 + 1.88679245283019*I*pi >>> p.q.n() 1.0 + 5.92753330865999*I >>> p.w_0.n() 0.00100000000000000 >>> p.z_r.n() 5.92753330865999 >>> from sympy.physics.optics import FreeSpace >>> fs = FreeSpace(10) >>> p1 = fs*p >>> p.w.n() 0.00101413072159615 >>> p1.w.n() 0.00210803120913829 See Also ======== RayTransferMatrix References ========== .. [1] https://en.wikipedia.org/wiki/Complex_beam_parameter .. [2] https://en.wikipedia.org/wiki/Gaussian_beam Nct|}t|}t|}|| t|}n*||tt|||}n| | tdtj|||||S)NzMust specify one of w and z_r.)rr r)rr+)r-r8zr5wns r0r+zBeamParameter.__new__sw'" AJ AJ ?qy#,C ]s{ Wa8C [QY=> >||C!S!44r1c |jdS)Nrr.r>s r0r8zBeamParameter.wavelen yy|r1c |jdS)Nr"rtr>s r0rpzBeamParameter.z$rur1c |jdS)Nr#rtr>s r0r5zBeamParameter.z_r(rur1c |jdS)Nr$rtr>s r0rrzBeamParameter.n,rur1cB|jt|jzzS)a The complex parameter representing the beam. Examples ======== >>> from sympy.physics.optics import BeamParameter >>> p = BeamParameter(530e-9, 1, w=1e-3) >>> p.q 1 + 1.88679245283019*I*pi )rprr5r>s r0r6zBeamParameter.q0svv$(( ""r1cZ|jd|j|jz dzzzS)a The radius of curvature of the phase front. Examples ======== >>> from sympy.physics.optics import BeamParameter >>> p = BeamParameter(530e-9, 1, w=1e-3) >>> p.radius 1 + 3.55998576005696*pi**2 r"r#)rpr5r>s r0radiuszBeamParameter.radius?s)vvqDHHTVVOa//00r1cl|jtd|j|jz dzzzS)a The radius of the beam w(z), at any position z along the beam. The beam radius at `1/e^2` intensity (axial value). See Also ======== w_0 : The minimal radius of beam. Examples ======== >>> from sympy.physics.optics import BeamParameter >>> p = BeamParameter(530e-9, 1, w=1e-3) >>> p.w 0.001*sqrt(0.2809/pi**2 + 1) r"r#)w_0rrpr5r>s r0rqzBeamParameter.wNs.(xxQ$&&/A!55666r1cnt|jt|jzz |jzS)ar The minimal radius of beam at `1/e^2` intensity (peak value). See Also ======== w : the beam radius at `1/e^2` intensity (axial value). Examples ======== >>> from sympy.physics.optics import BeamParameter >>> p = BeamParameter(530e-9, 1, w=1e-3) >>> p.w_0 0.00100000000000000 )rr5rrrr8r>s r0r}zBeamParameter.w_0ds)$DHHbi(566r1cB|jtz |jz S)z Half of the total angular spread. Examples ======== >>> from sympy.physics.optics import BeamParameter >>> p = BeamParameter(530e-9, 1, w=1e-3) >>> p.divergence 0.00053/pi )r8rr}r>s r0 divergencezBeamParameter.divergencexs||Btxx''r1cBt|j|jS)z The Gouy phase. Examples ======== >>> from sympy.physics.optics import BeamParameter >>> p = BeamParameter(530e-9, 1, w=1e-3) >>> p.gouy atan(0.53/pi) )rrpr5r>s r0gouyzBeamParameter.gouysTVVTXX&&r1c.d|jztz S)a The minimal waist for which the gauss beam approximation is valid. Explanation =========== The gauss beam is a solution to the paraxial equation. For curvatures that are too great it is not a valid approximation. Examples ======== >>> from sympy.physics.optics import BeamParameter >>> p = BeamParameter(530e-9, 1, w=1e-3) >>> p.waist_approximation_limit 1.06e-6/pi r#)r8rr>s r0waist_approximation_limitz'BeamParameter.waist_approximation_limits&~b  r1)NNr")rGrHrIrJr+rKr8rpr5rrr6r{rqr}rrrr=r1r0r r s-d 5 # # 1 177*77& ( ( ' '!!r1r cPtt||f\}}|dz|ztz|z S)a^ Calculate the rayleigh range from the waist of a gaussian beam. See Also ======== rayleigh2waist, BeamParameter Examples ======== >>> from sympy.physics.optics import waist2rayleigh >>> from sympy import symbols >>> w, wavelen = symbols('w wavelen') >>> waist2rayleigh(w, wavelen) pi*w**2/wavelen r#)rVrr)rqr8rrs r0r r s/$Wq'l+JAw a46"9W r1cVtt||f\}}t|tz |zS)ajCalculate the waist from the rayleigh range of a gaussian beam. See Also ======== waist2rayleigh, BeamParameter Examples ======== >>> from sympy.physics.optics import rayleigh2waist >>> from sympy import symbols >>> z_r, wavelen = symbols('z_r wavelen') >>> rayleigh2waist(z_r, wavelen) sqrt(wavelen*z_r)/sqrt(pi) )rVrrr)r5r8s r0r r s+"wg/LC Bw r1ctt||f\}}|js |jr|jr|S|S||z||zz S)a Conjugation relation for geometrical beams under paraxial conditions. Explanation =========== Takes the distances to the optical element and returns the needed focal distance. See Also ======== geometric_conj_af, geometric_conj_bf Examples ======== >>> from sympy.physics.optics import geometric_conj_ab >>> from sympy import symbols >>> a, b = symbols('a b') >>> geometric_conj_ab(a, b) a*b/(a + b) )rVr is_infinite)abs r0r r sH0 wA DAq}} MMq(q(sAE{r1cHtt||f\}}t||  S)a Conjugation relation for geometrical beams under paraxial conditions. Explanation =========== Takes the object distance (for geometric_conj_af) or the image distance (for geometric_conj_bf) to the optical element and the focal distance. Then it returns the other distance needed for conjugation. See Also ======== geometric_conj_ab Examples ======== >>> from sympy.physics.optics.gaussopt import geometric_conj_af, geometric_conj_bf >>> from sympy import symbols >>> a, b, f = symbols('a b f') >>> geometric_conj_af(a, f) a*f/(a - f) >>> geometric_conj_bf(b, f) b*f/(b - f) )rVrr )rrfs r0rrs*6 wA DAq a! $ $$r1ctt|||f\}}}dd||dz||z z zz d|z zz }dtd||z dzz ||z dzzz }|d||z dzz ||z dzzz }|||fS)a Conjugation relation for gaussian beams. Parameters ========== s_in : The distance to optical element from the waist. z_r_in : The rayleigh range of the incident beam. f : The focal length of the optical element. Returns ======= a tuple containing (s_out, z_r_out, m) s_out : The distance between the new waist and the optical element. z_r_out : The rayleigh range of the emergent beam. m : The ration between the new and the old waists. Examples ======== >>> from sympy.physics.optics import gaussian_conj >>> from sympy import symbols >>> s_in, z_r_in, f = symbols('s_in z_r_in f') >>> gaussian_conj(s_in, z_r_in, f)[0] 1/(-1/(s_in + z_r_in**2/(-f + s_in)) + 1/f) >>> gaussian_conj(s_in, z_r_in, f)[1] z_r_in/(1 - s_in**2/f**2 + z_r_in**2/f**2) >>> gaussian_conj(s_in, z_r_in, f)[2] 1/sqrt(1 - s_in**2/f**2 + z_r_in**2/f**2) r"rer#)rVrr)s_inz_r_inrfs_outmz_r_outs r0rrsR'D&!#45OD&! "dVQYq112QqS8 :E $T!VaKF1Hq=0 11Ad1fq[VAXM9:G 7A r1c tt|||f\}}}||z }t||}t|dk7r t dd|vrt t dd|vrBt|d}|dtd|dzz |dz|dzz z z z}t|||d}n,d|vrt t dt t d |||fS) a Find the optical setup conjugating the object/image waists. Parameters ========== wavelen : The wavelength of the beam. waist_in and waist_out : The waists to be conjugated. f : The focal distance of the element used in the conjugation. Returns ======= a tuple containing (s_in, s_out, f) s_in : The distance before the optical element. s_out : The distance after the optical element. f : The focal distance of the optical element. Examples ======== >>> from sympy.physics.optics import conjugate_gauss_beams >>> from sympy import symbols, factor >>> l, w_i, w_o, f = symbols('l w_i w_o f') >>> conjugate_gauss_beams(l, w_i, w_o, f=f)[0] f*(1 - sqrt(w_i**2/w_o**2 - pi**2*w_i**4/(f**2*l**2))) >>> factor(conjugate_gauss_beams(l, w_i, w_o, f=f)[1]) f*w_o**2*(w_i**2/w_o**2 - sqrt(w_i**2/w_o**2 - pi**2*w_i**4/(f**2*l**2)))/w_i**2 >>> conjugate_gauss_beams(l, w_i, w_o, f=f)[2] f r"z,The function expects only one named argumentdistzD Currently only focal length is supported as a parameterrfr#rrzG The functions expects the focal length as a named argument) rVrr r&r)NotImplementedErrorrrr) r8waist_in waist_outkwargsrrprfrrs r0rrKsV$'w(I0N#O GXyHAx)A 6{aGHH 6 !*.G#HI I  F3K AQq!tVad1a4i/001dAq)!, 6 !*.G#HI I%JKL L % r1Nr3)'rJ__all__sympy.core.exprrsympy.core.numbersrrsympy.core.sympifyr$sympy.functions.elementary.complexesrr(sympy.functions.elementary.miscellaneousr(sympy.functions.elementary.trigonometricrsympy.matrices.denserrsympy.polys.rationaltoolsrsympy.utilities.miscrrrrrrrrr r r r r rrrrr=r1r0rs. (!&&99:;.+N*Nb:!::>&>B K( KF:":,=$=<= =FT%TvJ!DJ!b, *>%<&-`=r1