예제 #1
0
def test_lens_makers_formula():
    n1, n2 = symbols('n1, n2')
    m1 = Medium('m1', permittivity=e0, n=1)
    m2 = Medium('m2', permittivity=e0, n=1.33)
    assert lens_makers_formula(n1, n2, 10, -10) == 5 * n2 / (n1 - n2)
    assert round(lens_makers_formula(m1, m2, 10, -10), 2) == -20.15
    assert round(lens_makers_formula(1.33, 1, 10, -10), 2) == 15.15
예제 #2
0
def test_refraction_angle():
    n1, n2 = symbols('n1, n2')
    m1 = Medium('m1')
    m2 = Medium('m2')
    r1 = Ray3D(Point3D(-1, -1, 1), Point3D(0, 0, 0))
    i = Matrix([1, 1, 1])
    n = Matrix([0, 0, 1])
    normal_ray = Ray3D(Point3D(0, 0, 0), Point3D(0, 0, 1))
    P = Plane(Point3D(0, 0, 0), normal_vector=[0, 0, 1])
    assert refraction_angle(r1, 1, 1, n) == Matrix([[1], [1], [-1]])
    assert refraction_angle([1, 1, 1], 1, 1, n) == Matrix([[1], [1], [-1]])
    assert refraction_angle((1, 1, 1), 1, 1, n) == Matrix([[1], [1], [-1]])
    assert refraction_angle(i, 1, 1, [0, 0, 1]) == Matrix([[1], [1], [-1]])
    assert refraction_angle(i, 1, 1, (0, 0, 1)) == Matrix([[1], [1], [-1]])
    assert refraction_angle(i, 1, 1, normal_ray) == Matrix([[1], [1], [-1]])
    assert refraction_angle(i, 1, 1, plane=P) == Matrix([[1], [1], [-1]])
    assert refraction_angle(r1, 1, 1, plane=P) == \
        Ray3D(Point3D(0, 0, 0), Point3D(1, 1, -1))
    assert refraction_angle(r1, m1, 1.33, plane=P) == \
        Ray3D(Point3D(0, 0, 0), Point3D(100/133, 100/133, -789378201649271*sqrt(3)/1000000000000000))
    assert refraction_angle(r1, 1, m2, plane=P) == \
        Ray3D(Point3D(0, 0, 0), Point3D(1, 1, -1))
    assert 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)))
    assert refraction_angle(r1, 1.33, 1, plane=P) == 0  # TIR
    assert refraction_angle(r1, 1, 1, normal_ray) == \
        Ray3D(Point3D(0, 0, 0), direction_ratio=[1, 1, -1])
예제 #3
0
def test_refraction_angle():
    n1, n2 = symbols('n1, n2')
    m1 = Medium('m1')
    m2 = Medium('m2')
    r1 = Ray3D(Point3D(-1, -1, 1), Point3D(0, 0, 0))
    i = Matrix([1, 1, 1])
    n = Matrix([0, 0, 1])
    normal_ray = Ray3D(Point3D(0, 0, 0), Point3D(0, 0, 1))
    P = Plane(Point3D(0, 0, 0), normal_vector=[0, 0, 1])
    assert refraction_angle(r1, 1, 1, n) == Matrix([[1], [1], [-1]])
    assert refraction_angle([1, 1, 1], 1, 1, n) == Matrix([[1], [1], [-1]])
    assert refraction_angle((1, 1, 1), 1, 1, n) == Matrix([[1], [1], [-1]])
    assert refraction_angle(i, 1, 1, [0, 0, 1]) == Matrix([[1], [1], [-1]])
    assert refraction_angle(i, 1, 1, (0, 0, 1)) == Matrix([[1], [1], [-1]])
    assert refraction_angle(i, 1, 1, normal_ray) == Matrix([[1], [1], [-1]])
    assert refraction_angle(i, 1, 1, plane=P) == Matrix([[1], [1], [-1]])
    assert refraction_angle(r1, 1, 1, plane=P) == \
        Ray3D(Point3D(0, 0, 0), Point3D(1, 1, -1))
    assert refraction_angle(r1, m1, 1.33, plane=P) == \
        Ray3D(Point3D(0, 0, 0), Point3D(Rational(100, 133), Rational(100, 133), -789378201649271*sqrt(3)/1000000000000000))
    assert refraction_angle(r1, 1, m2, plane=P) == \
        Ray3D(Point3D(0, 0, 0), Point3D(1, 1, -1))
    assert 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)))
    assert refraction_angle(r1, 1.33, 1, plane=P) == 0  # TIR
    assert refraction_angle(r1, 1, 1, normal_ray) == \
        Ray3D(Point3D(0, 0, 0), direction_ratio=[1, 1, -1])
    assert ae(refraction_angle(0.5, 1, 2), 0.24207, 5)
    assert ae(refraction_angle(0.5, 2, 1), 1.28293, 5)
    raises(ValueError, lambda: refraction_angle(r1, m1, m2, normal_ray, P))
    raises(TypeError, lambda: refraction_angle(m1, m1, m2)
           )  # can add other values for arg[0]
    raises(TypeError, lambda: refraction_angle(r1, m1, m2, None, i))
    raises(TypeError, lambda: refraction_angle(r1, m1, m2, m2))
예제 #4
0
def test_brewster_angle():
    m1 = Medium('m1', n=1)
    m2 = Medium('m2', n=1.33)
    assert round(brewster_angle(m1, m2), 2) == 0.93
    m1 = Medium('m1', permittivity=e0, n=1)
    m2 = Medium('m2', permittivity=e0, n=1.33)
    assert round(brewster_angle(m1, m2), 2) == 0.93
예제 #5
0
파일: test_utils.py 프로젝트: msgoff/sympy
def test_fresnel_coefficients():
    assert all(
        ae(i, j, 5)
        for i, j in zip(
            fresnel_coefficients(0.5, 1, 1.33), [0.11163, -0.17138, 0.83581, 0.82862]
        )
    )
    assert all(
        ae(i, j, 5)
        for i, j in zip(
            fresnel_coefficients(0.5, 1.33, 1), [-0.07726, 0.20482, 1.22724, 1.20482]
        )
    )
    m1 = Medium("m1")
    m2 = Medium("m2", n=2)
    assert all(
        ae(i, j, 5)
        for i, j in zip(
            fresnel_coefficients(0.3, m1, m2), [0.31784, -0.34865, 0.65892, 0.65135]
        )
    )
    ans = [[-0.23563, -0.97184], [0.81648, -0.57738]]
    got = fresnel_coefficients(0.6, m2, m1)
    for i, j in zip(got, ans):
        for a, b in zip(i.as_real_imag(), j):
            assert ae(a, b, 5)
예제 #6
0
파일: test_utils.py 프로젝트: msgoff/sympy
def test_lens_makers_formula():
    n1, n2 = symbols("n1, n2")
    m1 = Medium("m1", permittivity=e0, n=1)
    m2 = Medium("m2", permittivity=e0, n=1.33)
    assert lens_makers_formula(n1, n2, 10, -10) == 5 * n2 / (n1 - n2)
    assert ae(lens_makers_formula(m1, m2, 10, -10), -20.15, 2)
    assert ae(lens_makers_formula(1.33, 1, 10, -10), 15.15, 2)
예제 #7
0
def test_brewster_angle():
    m1 = Medium('m1', n=1)
    m2 = Medium('m2', n=1.33)
    assert ae(brewster_angle(m1, m2), 0.93, 2)
    m1 = Medium('m1', permittivity=e0, n=1)
    m2 = Medium('m2', permittivity=e0, n=1.33)
    assert ae(brewster_angle(m1, m2), 0.93, 2)
    assert ae(brewster_angle(1, 1.33), 0.93, 2)
예제 #8
0
def test_lens_makers_formula_thick_lens():
    n1, n2 = symbols('n1, n2')
    m1 = Medium('m1', permittivity=e0, n=1)
    m2 = Medium('m2', permittivity=e0, n=1.33)
    assert ae(lens_makers_formula(m1, m2, 10, -10, d=1), -19.82, 2)
    assert lens_makers_formula(
        n1, n2, 1, -1,
        d=0.1) == n2 / ((2.0 - (0.1 * n1 - 0.1 * n2) / n1) * (n1 - n2))
def test_fresnel_coefficients():
    assert list(round(i, 5) for i in fresnel_coefficients(0.5, 1, 1.33)) == \
        [0.11163, -0.17138, 0.83581, 0.82862]
    assert list(round(i, 5) for i in fresnel_coefficients(0.5, 1.33, 1)) == \
            [-0.07726, 0.20482, 1.22724, 1.20482]
    m1 = Medium('m1')
    m2 = Medium('m2', n=2)
    assert list(round(i, 5) for i in fresnel_coefficients(0.3, m1, m2)) == \
        [0.31784, -0.34865, 0.65892, 0.65135]
    assert list(list(round(j, 5) for j in i.as_real_imag()) for i in \
            fresnel_coefficients(0.6, m2, m1)) == \
        [[-0.23563, -0.97184], [0.81648, -0.57738]]
예제 #10
0
def test_deviation():
    n1, n2 = symbols('n1, n2')
    m1 = Medium('m1')
    m2 = Medium('m2')
    r1 = Ray3D(Point3D(-1, -1, 1), Point3D(0, 0, 0))
    n = Matrix([0, 0, 1])
    i = Matrix([-1, -1, -1])
    normal_ray = Ray3D(Point3D(0, 0, 0), Point3D(0, 0, 1))
    P = Plane(Point3D(0, 0, 0), normal_vector=[0, 0, 1])
    assert deviation(r1, 1, 1, normal=n) == 0
    assert deviation(r1, 1, 1, plane=P) == 0
    assert deviation(r1, 1, 1.1, plane=P).evalf(3) + 0.119 < 1e-3
    assert deviation(i, 1, 1.1, normal=normal_ray).evalf(3) + 0.119 < 1e-3
    assert deviation(r1, 1.33, 1, plane=P) is None  # TIR
    assert deviation(r1, 1, 1, normal=[0, 0, 1]) == 0
    assert deviation([-1, -1, -1], 1, 1, normal=[0, 0, 1]) == 0
예제 #11
0
def test_lens_makers_formula_plano_lens():
    n1, n2 = symbols('n1, n2')
    m1 = Medium('m1', permittivity=e0, n=1)
    m2 = Medium('m2', permittivity=e0, n=1.33)
    assert ae(lens_makers_formula(m1, m2, 10, oo), -40.30, 2)
    assert lens_makers_formula(n1, n2, 10, oo) == 10.0 * n2 / (n1 - n2)
예제 #12
0
def test_critical_angle():
    m1 = Medium('m1', n=1)
    m2 = Medium('m2', n=1.33)
    assert ae(critical_angle(m2, m1), 0.85, 2)
def test_critical_angle():
    m1 = Medium('m1', n=1)
    m2 = Medium('m2', n=1.33)
    assert round(critical_angle(m2, m1), 2) == 0.85
예제 #14
0
파일: test_utils.py 프로젝트: msgoff/sympy
def test_critical_angle():
    m1 = Medium("m1", n=1)
    m2 = Medium("m2", n=1.33)
    assert ae(critical_angle(m2, m1), 0.85, 2)