def create_axicon(angle: float, is_isosceles: bool, lenght_of_side_ribs: float, is_closed: bool, refr_coef_inside: float, refr_coef_outside: float): """ :param angle: the angle betweet OX and side rib (degree from 0 to 90) :param is_isosceles: if true, then the triangle is isosceles. Else rectangular. :param lenght_of_side_ribs: more than 0 :param is_closed: if true, then list surfaces have 3 objects. Else 2. :return: list of the limited surfaces. Two vertex of axicon is on OX. One at point (0,0) """ if not (refr_coef_inside >= 1 and refr_coef_outside >= 1): return None if not (angle > 0 and angle < 90): return None if not (lenght_of_side_ribs > 0): return None refr_coef = [refr_coef_inside, refr_coef_outside] length = lenght_of_side_ribs angle = angle * np.pi / 180 sinA = np.sin(angle) cosA = -np.cos(angle) dir_vec = [cosA, sinA] x, y = [val * length for val in dir_vec] m = [[0, -1], [1, 0]] norm = list(np.dot(dir_vec, m)) line1 = Plane([0, 0], norm, Surface.types.REFRACTING, n1=refr_coef[0], n2=refr_coef[1]) line2 = None if is_isosceles: norm2 = norm.copy() norm2[1] *= -1 line2 = Plane([0, 0], norm2, Surface.types.REFRACTING, n1=refr_coef[0], n2=refr_coef[1]) else: line2 = Plane([0, 0], [0, -1], Surface.types.REFRACTING, n1=refr_coef[0], n2=refr_coef[1]) limits1 = [[x, 0], [0, y]] limits2 = [[x, 0], [-y, 0]] line1 = LimitedSurface(line1, limits1) line2 = LimitedSurface(line2, limits2) if is_closed: line3 = Plane([x, 0], [-1, 0], Surface.types.REFRACTING, n1=refr_coef[0], n2=refr_coef[1]) limits3 = [[x - np.finfo(float).eps, x + np.finfo(float).eps], [-y, y]] if not is_isosceles: limits3[1] = [0, y] line3 = LimitedSurface(line3, limits3) return (line1, line2, line3) return (line1, line2)
def draw_limits(surface: LimitedSurface, color: str = "black", alpha: float = 0.5): lim = surface.limits planes = [ Plane([lim[0][0], 0], [1, 0]), Plane([lim[0][1], 0], [1, 0]), Plane([0, lim[1][0]], [0, 1]), Plane([0, lim[1][1]], [0, 1]), ] for plane in planes: draw_plane(plane, color=color, alpha=alpha)
def tracing(): # make pool points = ((-1, -1), (-0.9, 1)) pool = Generator.generate_rays_2d(points[0], points[1], 5.) sq2 = np.sqrt(2) vec_jonson = [1 / sq2, complex(1, -1) / sq2] # vec_jonson = [1, 1] for i in range(len(pool)): pool.set_jones_vec(i, vec_jonson) # make plane norm = [1, 0] start = [0, 0] n1, n2 = 1, 1.33 polar_mat = PolarMat(Generator.get_rot_mat_2d(np.pi / 4)) plane = Plane(start, norm, type_surface=Plane.types.REFRACTING, n1=n1, n2=n2) plane.polar_matrix_refract = polar_mat surfaces = (plane,) # make param for tracing method add_functions = (rpc.change_ray_polar_state,) # trace pool_list = rpc.raytracing_ordered_surface_with_add_opt(pool, surfaces, False, add_functions) # drawing # scene pylab.figure(0) # surfaces for surface in surfaces: surface_view.draw_exist_surface(surface) # rays for pool_to_draw in pool_list: ray_view.draw_ray_pool(pool_to_draw) pylab.grid() pylab.xlim(-2, 4) pylab.ylim(-2, 2) pylab.title( "Polarized light passed throw polarising surface\nPolarization matrix is a rotating matrix on angle pi/4") pylab.show() # polar state for every pool for i in range(len(pool_list)): pylab.figure(2 + i) vec_jo_to_draw = pool_list[i].jones_vec(0) title = f"Polar state for {i + 1} bean\n" + polarization.get_str_view_polar_vec(vec_jo_to_draw) polarization.draw_polar_ellipse(vec_jo_to_draw, title=title) pylab.grid() pylab.show()
def main(): center = [1, 2, 1] abc = [1, 1, 1] ray: Ray = Ray([0, 0, 0], [1, 1, 1]) ellipse1 = Ellipse(center=center, ellipse_coefficients=abc, type_surface=Ellipse.types.REFRACTING, n1=1, n2=1.33) plane = Plane([1, 1, 1], [0, 1, 1], type_surface=Ellipse.types.REFRACTING, n1=1, n2=1.33) # way_point_of_ray = mctrl.model_path(ray, [ellipse1], is_have_ray_in_infinity=True) way_point_of_ray2 = mctrl.model_path(ray, [plane], is_have_ray_in_infinity=True) fig = plt.figure() ax = Axes3D(fig) ax.set_xlabel('X Label') ax.set_ylabel('Y Label') ax.set_zlabel('Z Label') # ellipse(ax, ellipse1.abc, ellipse1.center) # line(ax, way_point_of_ray[0], way_point_of_ray[1], way_point_of_ray[2], "g") line(ax, way_point_of_ray2[0], way_point_of_ray2[1], way_point_of_ray2[2], "g") plot_plane(ax, plane) plt.show()
def get_plane_for_axicon(apex: List[Union[float, int]], height: (float, int), axis: str) -> Plane: """ :return: object Plane locating in the base of cone :param apex apex of cone :param height height of the cone. It can be negative, but never be close to zero. Positive value mean :param type_of_surface type of surface. See Surface.types. :param axis - axis of space along what axicon is located. The first char mean axis along what axicon is located("x","y","z"). :param n1 and n2 - refractive indexes of space. watch method get_refractive_indexes in class Surface :param kwargs - arguments for Surface class such as "polarisation_matrix_refract" or "polarisation_matrix_reflect""" if axis not in ("x", "y", "z"): raise ValueError(f"""The axis value is wrong - {axis}. It must have length 1. The first char mean axis along what cone is located("x","y","z"). """) normal = None if axis == "x": normal = (1, 0, 0) elif axis == "y": normal = (0, 1, 0) else: normal = (0, 0, 1) # center of the circle is the radius vector of the plane r_vec = np.add(apex, np.multiply(height, normal)) normal = np.multiply(np.sign(height), normal) return Plane(r_vec, normal)
def func_of_reading_surf_ray_from_strings(strings, dimension): d = dimension rays = [] surfaces = [] for s in strings: nums = np.fromstring(s[3:], dtype=float, count=-1, sep=' ') # p = plane s = sphere e = ellipse if s[0] == 'r': rays.append(Ray(nums[:d], nums[d:2 * d])) else: surface = None if s[0] == 'p': if s[1] == 't': surface = Plane(nums[:d], nums[d:2 * d], Surface.types.REFRACTING, nums[len(nums) - 2], nums[len(nums) - 1]) else: surface = Plane(nums[:d], nums[d:2 * d]) elif s[0] == 's': if s[1] == 't': surface = Sphere(nums[:d], nums[d], Surface.types.REFRACTING, nums[len(nums) - 2], nums[len(nums) - 1]) else: surface = Sphere(nums[:d], nums[d]) elif s[0] == 'e': if s[1] == 't': surface = Ellipse(nums[:d], nums[d:2 * d], Surface.types.REFRACTING, nums[len(nums) - 2], nums[len(nums) - 1]) else: surface = Ellipse(nums[:d], nums[d:2 * d]) if (surface != None): print('\tSUCCESS ' + str(surface)) surfaces.append(surface) return rays, surfaces
def draw_plane(plane: Plane, color="blue", alpha=0.5): # matrix of rotation m = [[0, -1], [1, 0]] # direction vector r = np.dot(m, plane.norm_vec([])) # coords = vray.collect_point_to_draw(r,) point = [ ARay.calc_point_of_ray_(r, plane.rad, 10_000), ARay.calc_point_of_ray_(r, plane.rad, -10_000) ] line = pylab.Line2D([point[i][0] for i in range(2)], [point[i][1] for i in range(2)], color=color, alpha=alpha) pylab.gca().add_line(line)
[2.8, 1]) axis_coeff = ([1.8, 2.5], [0.6, 0.3], [0.6, 0.28]) refr_indexes = ((1, 1.2), (1.2, 1.3), (1.2, 1.3)) surfaces = [] # for i in range(len(radius_vectors)): # surf = Ellipse(radius_vectors[i], axis_coeff[i], # n1=refr_indexes[i][0], n2=refr_indexes[i][1], # type_surface=Plane.types.REFRACTING) # surfaces.append(surf) # print(surf) for i in range(len(radius_vectors)): surf = Plane(radius_vectors[i], normal_vector=norm, n1=refr_indexes[i][0], n2=refr_indexes[i][1], type_surface=Plane.types.REFRACTING) surfaces.append(surf) print(surf) # %% from controllers.ray_pool_ctrl import * list_pool = deep_raytracing_with_add_opt(pool, surfaces, depth=4, surface_search_step=1) for i in range(len(list_pool)):
from surfaces.analitic.sphere import Surface from surfaces.limited_surface import LimitedSurface import view.matlab.matlab_ray_view2D as vray import view.matlab.matlab_surface_view2D as msv import controllers.ray_pool_ctrl as rpmc if __name__ == '__main__': p1 = [0, -1.9] p2 = [0, 1.9] intensive = 1 # plane n_vec = [1, -1] r_vec = [0, 0] plane = Plane(r_vec, n_vec) sphere = Sphere( [3, 0], 2, Surface.types.REFRACTING, 1, 1.3, ) lim = [[1, 3.9], [-1, 1]] print("lim", lim, "\n") print(plane) limited = LimitedSurface(sphere, lim) lim_plane = LimitedSurface(plane, lim)