Пример #1
0
    def test_dot_product_vector(self):
        print(">> test_dot_product_vector")
        v=Vector(0.,1.,0.)
        dot_product=v.dot(v)

        print(dot_product)
        assert_almost_equal(dot_product, 1., 15)
Пример #2
0
    def compound_specification_after_screen(self, beam, i):
        if self.type == "Wolter 1":
            if i == 1:

                vx = np.mean(beam.vx)
                vy = np.mean(beam.vy)
                vz = np.mean(beam.vz)

                v = Vector(vx, vy, vz)

                self.output_frame(beam, v, mode=1.)
                print(np.mean(beam.vx), np.mean(beam.vy), np.mean(beam.vz))

        if self.type == "Wolter 2":
            if i == 1:

                vx = np.mean(beam.vx)
                vy = np.mean(beam.vy)
                vz = np.mean(beam.vz)

                v = Vector(vx, vy, vz)

                self.output_frame(beam, v, mode=1.)

        if self.type == "Wolter 3":
            if self.oe[i].theta < 1e-10:

                vx = np.mean(beam.vx)
                vy = np.mean(beam.vy)
                vz = np.mean(beam.vz)

                v = Vector(vx, vy, vz)

                self.output_frame(beam, v, mode=1.)
Пример #3
0
    def trace_ideal_lens(self,beam1):

        beam=beam1.duplicate()


        t = self.p / beam.vy
        beam.x = beam.x + beam.vx * t
        beam.y = beam.y + beam.vy * t
        beam.z = beam.z + beam.vz * t

        gamma = np.arctan( beam.x/self.fx)
        alpha = np.arctan( -beam.z/self.fz)


        velocity = Vector(beam.vx, beam.vy, beam.vz)

        velocity.rotation(gamma, "z")
        velocity.rotation(alpha, "x")

        [beam.vx, beam.vy, beam.vz] = [velocity.x, velocity.y, velocity.z]


        #self.q=0
        t = self.q / beam.vy
        beam.x = beam.x + beam.vx * t
        beam.y = beam.y + beam.vy * t
        beam.z = beam.z + beam.vz * t

        beam.y *= 0.

        return beam
Пример #4
0
 def test_rotation_3(self):
     print(">> test_rotation_3")
     alpha=90*np.pi/180
     v = Vector(0,1,0)
     v.rotation(alpha,"y")
     print(v.info())
     assert_almost_equal ( v.x , 0.0 , 15)
     assert_almost_equal ( v.y , 1.0 , 15)
     assert_almost_equal ( v.z , 0.0 , 15)
Пример #5
0
 def test_rotation_2(self):
     print(">> test_rotation_2")
     theta=45*np.pi/180
     v = Vector(0,1,0)
     v.rotation(-(90*np.pi/180-theta),"x")
     print(v.info())
     assert_almost_equal ( v.x , 0.0 , 15)
     assert_almost_equal ( v.y , 1/np.sqrt(2) , 15)
     assert_almost_equal ( v.z , -1/np.sqrt(2) , 15)
Пример #6
0
 def test_rotation_1(self):
     print(">> test_rotation_1")
     theta=0*np.pi/180
     v = Vector(0,1,0)
     v.rotation(-(90*np.pi/180-theta),"x")
     print(v.info())
     assert_almost_equal ( v.x , 0.0 , 15)
     assert_almost_equal ( v.y , 0.0 , 15)
     assert_almost_equal ( v.z , -1.0 , 15)
Пример #7
0
    def test_sum_vector(self):
        print(">> test_sum_vector")
        v=Vector(0.,1.,0.)
        v2=v.sum(v)

        print(v2.info())
        assert_almost_equal(v2.x, 0.0, 15)
        assert_almost_equal(v2.y, 2., 15)
        assert_almost_equal(v2.z, 0., 15)
Пример #8
0
 def test_normalization_list_vector(self):
     print(">> test_normalization_list_vector")
     x = np.ones(10)
     y = np.ones(10)
     z = np.ones(10)
     v = Vector(x, y, z)
     v.normalization()
     assert_almost_equal(v.x, 1 / np.sqrt(3) * np.ones(10), 15)
     assert_almost_equal(v.y, 1 / np.sqrt(3) * np.ones(10), 15)
     assert_almost_equal(v.z, 1 / np.sqrt(3) * np.ones(10), 15)
Пример #9
0
 def test_rodrigues(self):
     print(">> test_rodrigues")
     theta=90*np.pi/180
     axis=Vector(0,0,1)
     v=Vector(0,1,0)
     vrot=v.rodrigues_formula(axis,theta)
     print(v.info())
     assert_almost_equal(vrot.x, -1.0, 15)
     assert_almost_equal(vrot.y, 0, 15)
     assert_almost_equal(vrot.z, 0, 15)
Пример #10
0
    def get_optical_axis_out(self, mode):

        if mode == 0:
            theta_grazing = np.pi/ 2 - self.oe[0].theta
            vx = np.tan(theta_grazing) / np.sqrt(1 + np.tan(theta_grazing) ** 2)
            return Vector(-vx, np.sqrt(1 - 2 * vx **2), vx)

        if mode == 1:
            theta_grazing = np.pi/ 2 - self.oe[0].theta
            vx = np.tan(theta_grazing) / np.sqrt(1 + 2 * np.tan(theta_grazing) ** 2)
            return Vector(-vx, np.sqrt(1 - 2 * vx **2), vx)
Пример #11
0
 def test_normalizationvector(self):
     print(">> test_normalizationvector")
     x=1
     y=1
     z=1
     v=Vector(x,y,z)
     v.normalization()
     print(v.info())
     assert_almost_equal(v.x, 1/np.sqrt(3), 15)
     assert_almost_equal(v.y, 1/np.sqrt(3), 15)
     assert_almost_equal(v.z, 1/np.sqrt(3), 15)
Пример #12
0
    def lens_output_direction(self,beam):

        gamma = np.arctan( beam.x/self.fx)
        alpha = np.arctan( -beam.y/self.fz)


        velocity = Vector(beam.vx, beam.vy, beam.vz)
        velocity.rotation(gamma, "y")
        velocity.rotation(alpha, "x")

        [beam.vx, beam.vy, beam.vz] = [velocity.x, velocity.y, velocity.z]
Пример #13
0
    def test_sum_list_vector(self):
        print(">> test_sum_list_vector")

        x=np.zeros(10)
        y=np.ones(10)
        z=np.zeros(10)
        v=Vector(x,y,z)
        v2=v.sum(v)
        assert_almost_equal(v2.x, np.zeros(10), 15)
        assert_almost_equal(v2.y, 2*np.ones(10), 15)
        assert_almost_equal(v2.z, np.zeros(10), 15)
Пример #14
0
    def mirror_output_direction(self,beam):

        if self.type == "Surface conical mirror":
            normal_conic = self.ccc_object.get_normal(np.array([beam.x, beam.y, beam.z]))
        elif self.type == "My hyperbolic mirror":
            normal_conic = self.ccc_object.get_normal(np.array([beam.x, beam.y, beam.z]))
        elif self.type == "Surface conical mirror 2":
            normal_conic = self.ccc_object.get_normal(np.array([beam.x, beam.y, beam.z]))

        normal = Vector(normal_conic[0,:],normal_conic[1,:], normal_conic[2,:])
        velocity = Vector(beam.vx, beam.vy, beam.vz)
        vperp = velocity.perpendicular_component(normal)
        v2 = velocity.sum(vperp)
        v2 = v2.sum(vperp)
        [beam.vx, beam.vy, beam.vz] = [v2.x, v2.y, v2.z]
Пример #15
0
    def trace_montel(self, beam, name_file=None, mode=0, p=None, q=None, theta_z=None, theta_x=None,
                     hitting_point=Vector(0., 0., 0.), output_frame=0., do_plot_footprint=False):


        #
        # p: is the source distance from the montel, q is the image plane distance from the montel, theta_z correspond to the incidence angle with the first yz-mirror
        # theta_x with the xy-mirror
        # hitting point are the coordinate where the beam hit the montel system
        # output fram = 0: image_plane that correspond to the two reflection beam
        # output fram = 1: image_plane that correspond to the no reflection beam
        #
        self.oe[0].set_parameters(p=p, q=q, theta=theta_z)
        self.oe[1].set_parameters(p=p, q=q, theta=theta_x)

        v_in = self.get_optical_axis_in(mode)

        self.input_frame(beam, v_in, mode, hitting_point)


        beam1, beam2, beam3 = self.apply_specular_reflections(beam, name_file,
                                    do_plot_footprint=do_plot_footprint)

        if output_frame == 0:
            v_out = self.get_optical_axis_out(mode)
        elif output_frame == 1:
            v_out = v_in

        self.output_frame(beam3[0], v_out, mode)
        self.output_frame(beam3[1], v_out, mode)
        self.output_frame(beam3[2], v_out, mode)


        return beam1, beam2, beam3
Пример #16
0
def theta():

    p = 0.23e-3
    f = 0.23e-3 / 2
    xp = 0.0127046
    yp = 0.350885
    m = xp / p

    v = Vector(xp, yp - f, 0.)
    v.normalization()
    t = Vector(xp / p, -1, 0.)
    t.normalization()

    print((np.arccos(v.dot(t))) * 180. / np.pi)

    return np.arccos(v.dot(t))
Пример #17
0
def tras_rot(beam, p):
    velocity = Vector(beam.vx, beam.vy, beam.vz)
    velocity.rotation(-gamma, 'z')
    velocity.rotation(-alpha, 'x')
    velocity.normalization()
    beam.vx = velocity.x
    beam.vy = velocity.y
    beam.vz = velocity.z

    position = Vector(beam.x, beam.y, beam.z)
    position.rotation(-gamma, 'z')
    position.rotation(-alpha, 'x')
    beam.x = position.x
    beam.y = position.y
    beam.z = position.z

    beam.x -= beam.vx[0] * p
    beam.y -= beam.vy[0] * p
    beam.z -= beam.vz[0] * p
Пример #18
0
    def set_flat_divergence_with_different_optical_axis(self, dx, dz):

        N = self.N

        x = self.vx
        z = self.vz
        y = self.vy

        self.vx = dx * (np.random.random(N) - 0.5) * 2
        self.vz = dz * (np.random.random(N) - 0.5) * 2
        self.vx = self.vx + x
        self.vz = self.vz + z

        velocity = Vector(self.vx, self.vy, self.vz)
        velocity.normalization()

        self.vx = velocity.x
        self.vy = velocity.y
        self.vz = velocity.z
Пример #19
0
def out(beam, q):
    print("\nOut")
    velocity = Vector(beam.vx, beam.vy, beam.vz)
    velocity.rotation(-alpha, 'x')
    print(velocity.x[0], velocity.y[0], velocity.z[0])
    velocity.rotation(-gamma, 'z')
    print(velocity.x[0], velocity.y[0], velocity.z[0])
    beam.vx = velocity.x
    beam.vy = velocity.y
    beam.vz = velocity.z

    position = Vector(beam.x, beam.y, beam.z)
    position.rotation(-alpha, 'x')
    position.rotation(-gamma, 'z')
    beam.x = position.x
    beam.y = position.y
    beam.z = position.z

    beam.retrace(q)
Пример #20
0
    def rotation(self, beam, angle, axis):
        velocity = Vector(beam.vx, beam.vy, beam.vz)
        position = Vector(beam.x, beam.y, beam.z)

        velocity.rotation(angle, axis)
        position.rotation(angle, axis)

        beam.x = position.x
        beam.y = position.y
        beam.z = position.z

        beam.vx = velocity.x
        beam.vy = velocity.y
        beam.vz = velocity.z
Пример #21
0
    def __init__(self, N=25000):

        N = round(N)

        self.x = np.zeros(N)
        self.y = np.zeros(N)
        self.z = np.zeros(N)

        velocity = Vector(0.0000001, 1., 0.01)
        velocity.normalization()

        self.vx = np.ones(N) * velocity.x
        self.vy = np.ones(N) * velocity.y
        self.vz = np.ones(N) * velocity.z

        self.flag = np.zeros(N)

        self.N = N

        self.indices = np.arange(self.N)

        self.aux = np.zeros(N)
Пример #22
0
    def translation_to_the_optical_element(self, beam):
        vector_point=Vector(0,self.p,0)
        vector_point.rotation(self.alpha,"y")
        vector_point.rotation(-(np.pi/2-self.theta),"x")

        beam.x=beam.x-vector_point.x
        beam.y=beam.y-vector_point.y
        beam.z=beam.z-vector_point.z
Пример #23
0
    def get_optical_axis_in(self, mode=0):

        theta_grazing_z = np.pi/ 2 - self.oe[0].theta
        theta_grazing_x = np.pi/ 2 - self.oe[1].theta

        if mode == 0:
            vz = np.tan(theta_grazing_z) / np.sqrt(1 + np.tan(theta_grazing_z) ** 2)
            vx = np.tan(theta_grazing_x) / np.sqrt(1 + np.tan(theta_grazing_x) ** 2)


        if mode == 1:
            vz = np.tan(theta_grazing_z) / np.sqrt(1 + np.tan(theta_grazing_z) ** 2 + np.tan(theta_grazing_x) ** 2)
            vx = np.tan(theta_grazing_x) / np.sqrt(1 + np.tan(theta_grazing_z) ** 2 + np.tan(theta_grazing_x) ** 2)


        return Vector(vx, np.sqrt(1 - vx**2 - vz**2), -vz)
Пример #24
0
    def test_rotation_10_array(self):
        print(">> test_rotation_10_array")
        theta = 45*np.pi/180
        alpha = 90*np.pi/180
        x=np.zeros(10)
        y=np.ones(10)
        z=np.zeros(10)
        v=Vector(x,y,z)
        v.rotation(alpha,"y")
        v.rotation(-(90*np.pi/180 - theta), "x")
        print (v.info())

        assert_almost_equal(v.x,np.zeros(10))
        assert_almost_equal(v.y,1/np.sqrt(2) *np.ones(10))
        assert_almost_equal(v.z,-1/np.sqrt(2)*np.ones(10))
Пример #25
0
    def rotation_to_the_optical_element(self, beam):

        position = Vector(beam.x,beam.y,beam.z)
        velocity = Vector(beam.vx,beam.vy,beam.vz)
        position.rotation(self.alpha,"y")
        position.rotation(-(np.pi/2-self.theta),"x")
        velocity.rotation(self.alpha,"y")
        velocity.rotation(-(np.pi/2-self.theta),"x")
        [beam.x,beam.y,beam.z] = [position.x,position.y,position.z]
        [beam.vx,beam.vy,beam.vz] = [velocity.x,velocity.y,velocity.z]
Пример #26
0
def tras_rot2(beam, p, theta):
    theta_grazing = np.pi / 2 - theta
    y = Vector(0., 1., 0.)
    y.rotation(-theta_grazing, 'x')
    x = Vector(1., 0., 0.)
    xp = x.vector_product(y)
    vrot = y.rodrigues_formula(xp, -theta_grazing)
    vrot.normalization()

    position = Vector(beam.x, beam.y, beam.z)
    velocity = Vector(beam.vx, beam.vy, beam.vz)
    position.rotation(-theta_grazing, 'x')
    velocity.rotation(-theta_grazing, 'x')
    #position = position.rodrigues_formula(xp, -theta_grazing)
    #velocity = velocity.rodrigues_formula(xp, -theta_grazing)
    velocity.normalization()
    beam.vx = velocity.x
    beam.vy = velocity.y
    beam.vz = velocity.z

    vector_point = Vector(0, p, 0)
    vector_point.rotation(-theta_grazing, "x")
    print(vector_point.info())
    #vector_point = vector_point.rodrigues_formula(xp, -theta_grazing)
    vector_point.normalization()

    beam.x = position.x - vector_point.x * p
    beam.y = position.y - vector_point.y * p
    beam.z = position.z - vector_point.z * p
Пример #27
0
#shadow_beam.rays[:, 16] = np.zeros(beam.N) + 0.0
#shadow_beam.rays[:, 17] = np.zeros(beam.N) + 0.0
#
#shadow_beam.write("beam_ollo.sha")
#
#
#beam.plot_xz(0)
#beam.plot_xpzp(0)
#

theta = 88. * np.pi / 180
theta_grazing = np.pi / 2 - theta

print("Start Vector")

y = Vector(0., 1., 0.)
y.z = -np.tan(theta_grazing) / np.sqrt(1 + np.tan(theta_grazing)**2)
y.x = +np.tan(theta_grazing) / np.sqrt(1 + np.tan(theta_grazing)**2)
y.y = np.sqrt(1 - y.x**2 - y.z**2)

y.x = y.x
y.y = y.y
y.z = y.z
print(y.x, y.y, y.z)

print(
    np.arctan(y.x / np.sqrt(y.y**2 + y.z**2)) * 180 / np.pi - 90.,
    90. + np.arctan(y.z / np.sqrt(y.y**2 + y.x**2)) * 180 / np.pi)

alpha = -np.arctan(y.z / y.y)
y.rotation(alpha, 'x')
Пример #28
0
    f = np.sqrt(ae**2 - be**2)

    b2 = beam.y
    b3 = beam.z
    beam.y = b3
    beam.z = b2
    beam.z = -beam.z + f

    p = wolter_japanese.oe[0].p
    q = wolter_japanese.oe[0].q

    beta = np.arccos((p**2 + 4 * f**2 - q**2) / (4 * p * f))
    y = -p * np.sin(beta)
    z = f - p * np.cos(beta)

    v = Vector(0., y, z - f)
    v.normalization()
    v0 = Vector(0., 0., -1.)
    v0.normalization()
    alpha = np.arccos(v.dot(v0))

    t = (-v.x * beam.x - v.y * beam.y -
         v.z * beam.z) / (v.x * beam.vx + v.y * beam.vy + v.z * beam.vz)
    beam.x += beam.vx * t
    beam.y += beam.vy * t
    beam.z += beam.vz * t

    velocity = Vector(beam.vx, beam.vz, -beam.vy)
    velocity.rotation(-alpha, 'x')

    beam.vx = velocity.x
Пример #29
0
    def rotation_to_the_screen(self,beam):

        position = Vector(beam.x,beam.y,beam.z)
        velocity = Vector(beam.vx,beam.vy,beam.vz)

        if self.type == "Ideal lens":
            position.rotation((np.pi/2-self.theta),"x")
            velocity.rotation((np.pi/2-self.theta),"x")
        else:
            position.rotation(-(np.pi/2-self.theta),"x")
            velocity.rotation(-(np.pi/2-self.theta),"x")
        [beam.x,beam.y,beam.z] = [position.x,position.y,position.z]
        [beam.vx,beam.vy,beam.vz] = [velocity.x,velocity.y,velocity.z]