def getblockkey(s_keyname, s_block): if s_keyname == 'SURFACE': c_surface = surface.surface() c_surface.readRMC(s_block) return c_surface if s_keyname == 'UNIVERSE': c_universe = universe.universe() c_universe.readRMC(s_block) return c_universe if s_keyname == 'MATERIAL': c_material = material.material() c_material.readRMC(s_block) return c_material # if s_keyname == 'CRITICALITY': # c_criticality = criticality.criticality() # c_criticality.readRMC(s_block) # return c_criticality # if s_keyname == 'PLOT': # c_plot = plot.plot() # c_plot.readRMC(s_block) # return c_plot else: return -1
def ParabolicReflector(foc_z: float, n_in=10): surface_list = [] """Make work both ways; start light at focus or start light incoming""" # Create a circular paraboloidal reflector along the z-axis with focus coordinate as given and vertex at origin # Focus is located at (0, 0, foc_z), foc_z = 1/(4a^2) # Equation of circular paraboloid: z = a(x^2 + y^2) a = .5 * math.sqrt(1 / foc_z) print("a: " + str(a)) # First, create ray starting points and isotropic rays # Coordinates of startingpoint -- same for all rays x = 0 y = 0 n = n_in # number of rays ray_startpoints = np.empty((n, 3)) ray_startpoints[..., 0] = x ray_startpoints[..., 1] = y ray_startpoints[..., 2] = foc_z # rays = initial [forward direction (3), s1 polarization axis (3), s0, s1, s2, s3] # Let s0 be 1 and rays be unpolarized (other Stokes parameters = 0 + no polarization axis) test_rays = np.zeros((n, 10)) test_rays[..., 3] = 1 test_rays[..., 6] = 1 # Assign initial forward directions in spherical coords for easier isotropism """These isotropic directions may be biased towards the origin, as they are not shifted for a non-origin starting point""" """ for i in range(n): azimuth = random.random() * 2 * math.pi ran_a = np.random.uniform(-1, 1) polar = np.arccos(ran_a) # -1 < theta < 1 so random numbers are not biased towards the pole test_rays[i, 0] = np.sin(polar) * np.cos(azimuth) # x test_rays[i, 1] = np.sin(polar) * np.sin(azimuth) # y test_rays[i, 2] = np.cos(polar) # z """ test_rays[0, 0] = 1 test_rays[0, 1] = 0 test_rays[0, 2] = -1 test_rays[1, 0] = -1 test_rays[1, 1] = 0 test_rays[1, 2] = -1 # Paraboloidal reflector consists of a single quadric surface reflector = surface.surface() reflector.description = "paraboloidal reflector with focus at (0, 0, " + str(foc_z) + ")" reflector.shape = 'quadsurface' reflector.param_list = [np.vstack(([a, 0, 0], [0, a, 0], [0, 0, 0])), np.array([0, 0, -1]), 0] reflector.inbounds_function = lambda p: np.reshape((p[:, 2, :] >= 0) * (p[:, 2, :] < 10), (p.shape[0], -1)) # cut off paraboloid at z = 10cm reflector.n_outside = np.inf reflector.n_inside = 1 reflector.surface_type = 'normal' reflector.absorption = 0 surface_list.append(reflector) return ray_startpoints, test_rays, surface_list
def add_surface(self, number, type_='standard', radius=1e10, thickness=0,\ conic=0, material='air', coating=None, semi_aperture=5, comment='',\ stop=False, *args, **kwargs): if stop: if self.stop is None: self.stop = number else: raise ValueError( 'Redefinition of stop position at surface %d' % number) self.num_surfaces += 1 self.surface_list.append(surface(number, self.wavelengths_list, type_=type_,\ radius=radius, thickness=thickness, conic=conic, material=material,\ coating=coating, semi_aperture=semi_aperture, comment=comment,\ stop=stop, *args, **kwargs))
def createGeometry(gs): # Initialize some containers rays = [] ray_startingpoints = [] pixels = [ ] # This will return empty because none of the code in this example defines the pixels # some useful equations # n0 = index of refraction at known density # r = rho/rho0 (rho = density now, rho0 = density corresponding to n0) # returns index of refraction at density rho # clausius_mossotti = @(n0, r)(sqrt(((1 + 2*r).*n0.*n0 + 2 - 2*r)./((1 - r).*n0.*n0 + 2 + r))); # Calculate some dimensions based on the values provided by geospecs (gs). These may be useful for defining some geometry vp_s = (gs.vp_focuslen - gs.vp_nip_top) * np.sin( gs.vp_theta) # % radial position of air-side center of viewport vp_elev = (gs.vp_focuslen - gs.vp_nip_top) * np.cos( gs.vp_theta ) + gs.vp_focuselev # % vertical position of air-side center of viewport t_o = np.array([0, gs.ojar_thick]) t_i = np.array([0, gs.ijar_thick]) r1 = np.array([gs.ojar_cylrad - t_o, gs.ijar_cylrad - t_i]) r2 = np.array([gs.ojar_knucklerad - t_o, gs.ijar_knucklerad - t_i]) r3 = np.array([gs.ojar_axrad - t_o, gs.ijar_axrad - t_i]) s = r3 * (r1 - r2) / (r3 - r2) # % axis to knuckle-dome transition z = r2 * np.sqrt(1 - (s / r3)**2) # % equator to knuckle-dome transition d = r3 * z * ((1 / r3) - (1 / r2)) # % equator to dome sphere center vp_axis = np.array([0, -np.sin(gs.vp_theta), np.cos(gs.vp_theta)]) vp_center = np.array([0, -vp_s, vp_elev]) head_out_Q = np.array([[gs.pv_rad**(-2), 0, 0], [0, gs.pv_rad**(-2), 0], [0, 0, gs.pv_axrad**(-2)]]) head_in_Q = np.array([[(gs.pv_rad - gs.pv_thick)**(-2), 0, 0], [0, (gs.pv_rad - gs.pv_thick)**(-2), 0], [0, 0, (gs.pv_axrad - gs.pv_thick)**(-2)]]) head_out_P = np.array([0, 0, -2 * gs.pv_top * (gs.pv_axrad**(-2))]) head_in_P = np.array( [0, 0, -2 * gs.pv_top * ((gs.pv_axrad - gs.pv_thick)**(-2))]) head_out_R = (gs.pv_top / gs.pv_axrad)**2 - 1 head_in_R = (gs.pv_top / (gs.pv_axrad - gs.pv_thick))**2 - 1 rd_cone_b = (gs.rdcone_toprad - gs.rd_rad) / (gs.rdcone_top - gs.rd_top) rd_cone_z0 = gs.rd_top - (gs.rd_rad / rd_cone_b) rd_cone_Q = np.array([[1, 0, 0], [0, 1, 0], [0, 0, -rd_cone_b**2]]) rd_cone_P = np.array([0, 0, 2 * (rd_cone_b**2) * rd_cone_z0]) rd_cone_R = -(rd_cone_b * rd_cone_z0)**2 rd_stcone_b = (gs.rdcone_toprad - gs.rdtopcone_rad) / (gs.rdtopcone_bot - gs.rdcone_top) rd_stcone_z0 = gs.rdtopcone_bot + (gs.rdtopcone_rad / rd_stcone_b) rd_stcone_Q = np.array([1, 0, 0], [0, 1, 0], [0, 0, -rd_stcone_b**2]) rd_stcone_P = np.array([0, 0, 2 * (rd_stcone_b**2) * rd_stcone_z0]) rd_stcone_R = -(rd_stcone_b * rd_stcone_z0)**2 rd_topcone_b = gs.rdtopcone_rad / (gs.rdtopcone_apex - gs.rdtopcone_bot) rd_topcone_Q = np.array([[1, 0, 0], [0, 1, 0], [0, 0, -rd_topcone_b**2]]) rd_topcone_P = np.array([0, 0, 2 * (rd_topcone_b**2) * gs.rdtopcone_apex]) rd_topcone_R = -(rd_topcone_b * gs.rdtopcone_apex)**2 rd_botcone_b = gs.rdbotcone_rad / (gs.rdbotcone_apex - gs.rdbotcone_bot) rd_botcone_Q = np.array([[1, 0, 0], [0, 1, 0], [0, 0, -rd_botcone_b**2]]) rd_botcone_P = np.array([0, 0, 2 * (rd_botcone_b**2) * gs.rdbotcone_apex]) rd_botcone_R = -(rd_botcone_b * gs.rdbotcone_apex)**2 # Define a surface list (where the geometry is actually constructed) # surface_list ={'description': None, 'intersect_function': None, 'inbounds_function': None, 'n_outside':None, 'n_inside':None, 'surface_type':None, 'absorption':None} surface_list = [] # Define some geometry (Do as many of these as necessary to define all geometry. Right now, we'll just do 2, + 1 bubble) # Define Surface #1 # instantiate the surface insideInnerCyl = surface.surface() # describe it insideInnerCyl.description = 'inside surface of inner quartz cylinder' # name its geometry type (options are cylinder, sphere, plane, torus, quadsurface) insideInnerCyl.shape = "cylinder" # define the shape's parameters insideInnerCyl.param_list = [[0, 0, 0], [0, 0, 1], r1[3]] # define the inbounds function of the geometry insideInnerCyl.inbounds_function = lambda p: np.reshape( (p[:, 2, :] < gs.ijar_elevation) and (p[:, 2, :] >= (gs.ijar_elevation - gs.ijar_cyllength)), (np.size(p, 0), -1)) # provide indexes of refraction insideInnerCyl.n_outside = gs.n_jar insideInnerCyl.n_inside = gs.n_hydraulic # provide surface_type and absorption parameters insideInnerCyl.surface_type = 'normal' insideInnerCyl.absorption = 0 # add the geometry to the list surface_list.append(insideInnerCyl) # Define surface #2 outsideInnerCyl = surface.surface() outsideInnerCyl.description = 'outside surface of inner quartz cylinder' outsideInnerCyl.shape = "cylinder" outsideInnerCyl.param_list = [[0, 0, 0], [0, 0, 1], r1[2]] outsideInnerCyl.inbounds_function = lambda p: np.reshape( (p[:, 2, :] < gs.ijar_elevation) and (p[:, 2, :] >= (gs.ijar_elevation - gs.ijar_cyllength)), (np.size(p, 0), -1)) outsideInnerCyl.n_outside = gs.n_target outsideInnerCyl.n_inside = gs.n_jar outsideInnerCyl.surface_type = 'normal' outsideInnerCyl.absorption = 0 surface_list.append(outsideInnerCyl) # handle the bubble if gs.bubble_present: bubble = surface.surface() bubble.description = 'bubble' bubble.shape = 'sphere' bubble.param_list = [gs.bubble_position, gs.bubble_radius] bubble.inbounds_function = lambda p: np.reshape( p[:, 2, :] > -500, (np.size(p, 0), -1)) bubble.n_outside = gs.n_target bubble.n_inside = gs.n_air bubble.surface_type = 'normal' bubble.absorption = 0 surface_list.append(bubble) # generate some light rays 0 this function won't work, it's just a placeholer # CreateSomeLightRays DNE [raydirections, pixelmap] = CreateSomeLightRays( gs.cam_resolution, cam_pixelpitch, .5 * (1 + gs.cam_resolution ), #What is 'cam_pixelpitch' for? All of these inputs? gs.cam_f, gs.cam_pitch + gs.vp_theta - (np.pi / 2), gs.cam_yaw, gs.cam_roll, gs.cam_barreld, gs.cam_lenstype) # add them to rays container in proper format that will help with calculation rays.append(raydirections) # do some math and get the ray starting points, and store them in the variable ray_startingpoints.append( np.matlib.repmat( vp_center + [gs.cam_x, 0, 0] + gs.cam_z * vp_axis + gs.cam_y * np.cross(vp_axis, [1, 0, 0]), (np.size(raydirections, 0), 1))) # Return the values return [surface_list, rays, ray_startingpoints, pixels]
def render(self): bf = self.current.render() return surface.surface(bf)
def main(): surface_list = [] # hemisphere hemi = surface.surface() hemi.description = '10cm radius hemisphere, in positive z' hemi.shape = 'sphere' hemi.param_list = [np.array([0, 0, 0]), 10] hemi.inbounds_function = lambda p: np.reshape( (p[:, 2, :] >= 0) * (p[:, 2, :] <= 10), (p.shape[0], -1)) hemi.n_outside = np.inf hemi.n_inside = 1.5 hemi.surface_type = 'normal' hemi.absorption = 1 surface_list.append(hemi) # panel panel = surface.surface() panel.description = 'retroreflecting panel cut to 10cm radius disk on xy-plane' panel.shape = 'plane' panel.param_list = [np.array([0, 0, 0]), np.array([0, 0, 1])] panel.inbounds_function = lambda p: np.reshape( (p[:, 0]**2 + p[:, 1]**2) < 100, (p.shape[0], -1)) panel.n_outside = 1.5 panel.n_inside = np.inf panel.surface_type = 'unified' panel.unifiedparams = [0, 0, .25, .5, .1] panel.absorption = 0 surface_list.append(panel) # construct light rays # start them along z-axis, pointing down for normal incidence # start at (-5, 0, 5), pointing towards origin for 45 degree incidence x = -5 y = 0 z = 5 n = 100 # number of rays ray_startpoints = np.empty((n, 3)) ray_startpoints[..., 0] = x ray_startpoints[..., 1] = y ray_startpoints[..., 2] = z # rays = initial [forward direction (3), s1 polarization axis (3), s0, s1, s2, s3] # Let s0 be 1 and rays be unpolarized (other Stokes parameters = 0 + no polarization axis) test_rays = np.zeros((n, 10)) test_rays[..., 3] = 1 test_rays[..., 6] = 1 test_rays[:, 0] = 1 test_rays[:, 1] = 0 test_rays[:, 2] = -1 [ray_interfaces, absorption_table, raytable] = RayTracer2.RayTracer2(ray_startpoints, test_rays, surface_list) # PLOT # calculate spherical coordinates x_int = ray_interfaces[1].intersection_point[:, 0] y_int = ray_interfaces[1].intersection_point[:, 1] z_int = ray_interfaces[1].intersection_point[:, 2] theta = np.arctan2(np.sqrt(x_int**2 + y_int**2), z_int) # 0 < theta < pi/2 phi = np.arctan2(y_int, x_int) # -pi < phi < pi phi[np.isnan(phi)] = 0 phi = (phi + 2 * math.pi) % (2 * math.pi) # convert to 0 < phi < 2pi # spherical coords of initial rays theta_0 = np.matlib.repmat(np.cos(np.arctan2(np.sqrt(x**2 + y**2), z)), len(theta), 1) phi_0 = np.matlib.repmat(np.arctan2(y, x), len(theta), 1) phi_0[np.isnan(phi_0)] = 0 #phi_0 = (phi_0 + 2 * math.pi) % (2 * math.pi) # Perfect Reflection Check points = np.concatenate((phi[:, np.newaxis], np.cos(theta)[:, np.newaxis]), axis=1) counts = np.equal(points, np.concatenate( (phi_0, np.cos(theta_0)), axis=1)) # cos(theta), phi the same fig, ax = plt.subplots() ax.scatter(phi, np.cos(theta)) plt.xlim(0, 2 * math.pi) plt.ylim(0, 1) ax.set_ylabel("cos\u03B8") # theta ax.set_xlabel("\u03C6 (azimuth)") # phi ax.grid(True) #print("intersection: " + str(ray_interfaces[1].intersection_point)) #print("points: " + str(points)) #print("counts: " + str(counts)) #print("check: " + str(np.concatenate((phi_0, np.cos(theta_0)), axis=1))) plt.text(.96, .08, "# rays perfectly reflected = {}".format(int(np.sum(counts))), bbox={ 'facecolor': 'w', 'pad': 5 }, ha="right", va="top", transform=plt.gca().transAxes) #check the counts/2 plt.show()
def render(self): sdl_sur = self.lib.Item_render(self.obj) sur = surface.surface(sdl_sur) return sur
def main(): surf = surface.surface('surface_1', 0, 0, 10, 10) rect = surf.getRect() print(rect)
scene.title = "Solid Collision Simulation" scene.background = (1., 1., 1.) scene.fullscreen = True scene.forward = (0.,1.,0.) scene.up = (0.,0.,1.) scene.center = (0.,-8.,8.) #scene.fov = pi/2. scene.range = 20 #curve(pos = [[0.,0.,0.],[1.,0.,0.]],color = color.red, radius = 0.05) #curve(pos = [[0.,0.,0.],[0.,1.,0.]],color = color.green, radius = 0.05) #curve(pos = [[0.,0.,0.],[0.,0.,1.]],color = color.blue, radius = 0.05) #Surface surface({'point':(-20.,-20.),'delta':(40.,40.)},.05) #Getting size of solids. list_of_size = get_size(n_sol, path) #Getting initial position of solids. list_of_pos, list_of_axis = get_initial_position(n_sol, path) #Creating the solids. list_of_solids = create_solids(n_sol,list_of_size,list_of_pos,list_of_axis) #Drawing each solid. for solid in list_of_solids: solid.draw() if (path == ''):
def TestGeometry(z_in): # First, create ray starting points and isotropic rays # Coordinates of startingpoint -- same for all rays x = 0 y = 0 z = z_in n = 10 # number of rays ray_startpoints = np.empty((n, 3)) ray_startpoints[..., 0] = x ray_startpoints[..., 1] = y ray_startpoints[..., 2] = z # rays = initial [forward direction (3), s1 polarization axis (3), s0, s1, s2, s3] # Let s0 be 1 and rays be unpolarized (other Stokes parameters = 0 + no polarization axis) test_rays = np.zeros((n, 10)) test_rays[..., 3] = 1 test_rays[..., 6] = 1 # Assign initial forward directions in spherical coords for easier isotropism for i in range(n): azimuth = random.random() * 2 * math.pi a = np.random.uniform(-1, 1) polar = np.arccos( a ) # -1 < theta < 1 so random numbers are not biased towards the pole test_rays[i, 0] = np.sin(polar) * np.cos(azimuth) # x test_rays[i, 1] = np.sin(polar) * np.sin(azimuth) # y test_rays[i, 2] = np.cos(polar) # z # Test geometry consists of 5 surfaces surface_list = [] # Bottom cylinder bot_cyl = surface.surface() bot_cyl.description = 'bottom cylinder along z-axis, 10cm radius from z=0 to z=5' bot_cyl.shape = 'cylinder' bot_cyl.param_list = [np.array([0, 0, 0]), np.array([0, 0, 1]), 10] bot_cyl.inbounds_function = lambda p: np.reshape( (p[:, 2, :] > 0) * (p[:, 2, :] < 5), (p.shape[0], -1)) bot_cyl.n_outside = 1.5 bot_cyl.n_inside = 1.5 bot_cyl.surface_type = 'unified' bot_cyl.unifiedparams = [0, 0, 0, 0, 0] bot_cyl.absorption = 0 surface_list.append(bot_cyl) # Top cylinder top_cyl = surface.surface() top_cyl.description = 'top cylinder along z-axis, 10cm radius from z=5 to z=10' top_cyl.shape = 'cylinder' top_cyl.param_list = [np.array([0, 0, 0]), np.array([0, 0, 1]), 10] top_cyl.inbounds_function = lambda p: np.reshape( (p[:, 2, :] >= 5) * (p[:, 2, :] < 10), (p.shape[0], -1)) top_cyl.n_outside = 1.5 top_cyl.n_inside = 2 top_cyl.surface_type = 'unified' top_cyl.unifiedparams = [0, 0, 0, 0, 0] top_cyl.absorption = 0 surface_list.append(top_cyl) # Top cap top = surface.surface() top.description = 'top cap, disk centered on z-axis with radius 10 and z=10' top.shape = 'plane' top.param_list = [np.array([0, 0, 10]), np.array([0, 0, 1])] top.inbounds_function = lambda p: np.reshape( (p[:, 0]**2 + p[:, 1]**2) < 100, (p.shape[0], -1)) # Direction of normal vector considered 'outside' top.n_outside = 1.5 top.n_inside = 2 top.surface_type = 'normal' top.absorption = 1 surface_list.append(top) # Middle mid = surface.surface() mid.description = 'middle disk centered on z-axis with radius 10 and z=5' mid.shape = 'plane' mid.param_list = [np.array([0, 0, 5]), np.array([0, 0, 1])] mid.inbounds_function = lambda p: np.reshape( (p[:, 0]**2 + p[:, 1]**2 < 100), (p.shape[0], -1)) mid.n_outside = 2 mid.n_inside = 1.5 mid.surface_type = 'normal' mid.absorption = 0 surface_list.append(mid) # Bottom cap bottom = surface.surface() bottom.description = 'bottom cap, disk centered on z-axis with radius 10 and z=0' bottom.shape = 'plane' bottom.param_list = [np.array([0, 0, 0]), np.array([0, 0, 1])] bottom.inbounds_function = lambda p: np.reshape( (p[:, 0]**2 + p[:, 1]**2 < 100), (p.shape[0], -1)) bottom.n_outside = 1.5 bottom.n_inside = 1.5 bottom.surface_type = 'normal' bottom.absorption = 1 surface_list.append(bottom) return ray_startpoints, test_rays, surface_list
def main(): surface_list = [] # hemisphere hemi = surface.surface() hemi.description = '10cm radius hemisphere, in positive z' hemi.shape = 'sphere' hemi.param_list = [np.array([0, 0, 0]), 10] hemi.inbounds_function = lambda p: np.reshape( (p[:, 2, :] >= 0) * (p[:, 2, :] <= 10), (p.shape[0], -1)) hemi.n_outside = np.inf hemi.n_inside = 1.5 hemi.surface_type = 'normal' hemi.absorption = 1 surface_list.append(hemi) # panel panel = surface.surface() panel.description = 'retroreflecting panel cut to 10cm radius disk on xy-plane' panel.shape = 'plane' panel.param_list = [np.array([0, 0, 0]), np.array([0, 0, 1])] panel.inbounds_function = lambda p: np.reshape( (p[:, 0]**2 + p[:, 1]**2) < 100, (p.shape[0], -1)) panel.n_outside = 1.5 panel.n_inside = np.inf panel.surface_type = 'unified' panel.unifiedparams = [0, 0, 0, 0, 0] panel.absorption = 0 surface_list.append(panel) # construct light rays # start them along z-axis, pointing down x = 0 y = 0 z = 5 n = 10000 # number of rays ray_startpoints = np.empty((n, 3)) ray_startpoints[..., 0] = x ray_startpoints[..., 1] = y ray_startpoints[..., 2] = z # rays = initial [forward direction (3), s1 polarization axis (3), s0, s1, s2, s3] # Let s0 be 1 and rays be unpolarized (other Stokes parameters = 0 + no polarization axis) test_rays = np.zeros((n, 10)) test_rays[..., 3] = 1 test_rays[..., 6] = 1 test_rays[:, 0] = 0 test_rays[:, 1] = 0 test_rays[:, 2] = -1 #print(test_rays) [ray_interfaces, absorption_table, raytable] = RayTracer2.RayTracer2(ray_startpoints, test_rays, surface_list) # print("Points of intersection:") # print(ray_interfaces[1].intersection_point) # print(ray_interfaces[1].intersection_point.shape) # calculate spherical coordinates x_int = ray_interfaces[1].intersection_point[:, 0] y_int = ray_interfaces[1].intersection_point[:, 1] z_int = ray_interfaces[1].intersection_point[:, 2] theta = np.arctan( (np.sqrt(x_int**2 + y_int**2) / z_int)) # 0 < theta < pi/2 phi = np.arctan( y_int / x_int) # 0 < phi < 2pi PROBLEM HERE: ARCTAN ONLY FROM -pi/2 --> pi/2 phi[np.isnan(phi)] = 0 points = np.concatenate((phi[:, np.newaxis], np.cos(theta)[:, np.newaxis]), axis=1) counts = np.equal(points, np.matlib.repmat(np.array([0, 1]), points.shape[0], 1)) print("# of Rays Perfectly Reflected: " + str(int(np.sum(counts) / 2))) fig, ax = plt.subplots() ax.scatter(phi, np.cos(theta)) plt.xlim(0, 2 * math.pi) plt.ylim(0, 1) ax.set_ylabel("cos\u03B8") # theta ax.set_xlabel("\u03C6") # phi ax.grid(True) plt.show()
def donut(n_in): surface_list = [] center = np.array([0, 0, 0]) ax = np.array([0, 0, 1]) r1 = 8 # large radius (from center of hole to center of tube) r2 = 2 # small radius (height) # First, create ray starting points and isotropic rays # Coordinates of startingpoint -- same for all rays x = 8.5 y = 0 z = .5 n = n_in # number of rays ray_startpoints = np.empty((n, 3)) ray_startpoints[..., 0] = x ray_startpoints[..., 1] = y ray_startpoints[..., 2] = z # rays = initial [forward direction (3), s1 polarization axis (3), s0, s1, s2, s3] # Let s0 be 1 and rays be unpolarized (other Stokes parameters = 0 + no polarization axis) test_rays = np.zeros((n, 10)) test_rays[..., 3] = 1 test_rays[..., 6] = 1 # Assign initial forward directions in spherical coords for easier isotropism """These isotropic directions may be biased towards the origin, as they are not shifted for a non-origin starting point""" for i in range(n): azimuth = random.random() * 2 * math.pi a = np.random.uniform(-1, 1) polar = np.arccos(a) # -1 < theta < 1 so random numbers are not biased towards the pole test_rays[i, 0] = np.sin(polar) * np.cos(azimuth) # x test_rays[i, 1] = np.sin(polar) * np.sin(azimuth) # y test_rays[i, 2] = np.cos(polar) # z # Donut consists of a single torus and outer sphere for collecting escaped rays reflector = surface.surface() reflector.description = "fully enclosed donut aligned on z-axis with center at origin" reflector.shape = 'torus' reflector.param_list = [center, ax, r1, r2] reflector.inbounds_function = lambda p: np.reshape(np.abs(p[:,2,:]) <= r2,(p.shape[0], -1)) reflector.n_outside = sys.float_info.max reflector.n_inside = 1 reflector.surface_type = 'normal' reflector.absorption = 0 surface_list.append(reflector) collector = surface.surface() collector.description = "spherical surface for checking for escaped rays" collector.shape = 'sphere' collector.param_list = [np.array([0, 0, 0]), 20] collector.inbounds_function = lambda p: np.reshape((p[:,0,:]**2 + p[:,1,:]**2 + p[:,2,:]**2) == 20**2, (p.shape[0], -1)) collector.n_outside = sys.float_info.max collector.n_inside = sys.float_info.max collector.surface_type = 'normal' collector.absorption = 1 surface_list.append(collector) return ray_startpoints, test_rays, surface_list
def get_radio_checked(self): return surface.surface(self.lib.Style_getRadioChecked(self.obj))
def surface(self): obj=surface()
def get_radio(self): return surface.surface(self.lib.Style_getRadio(self.obj))
def get_checkbox_checked(self): return surface.surface(self.lib.Style_getCheckboxChecked(self.obj))
def get_down_arrow(self): return surface.surface(self.lib.Style_getDownArrow(self.obj))
def get_up_arrow(self): return surface.surface(self.lib.Style_getUpArrow(self.obj))
def get_droplist_arrow(self): return surface.surface(self.lib.Style_getDropListArrow(self.obj))
import numpy as np from math import * import cv2 from point import * from light import light from player import player from surface import surface me = player() li = light() res = me.ppdist*2 img = np.zeros((res,res,3), np.uint8) mytri = surface('tri', point(0,10,0), point(10,20,0), point(0,30,10)) k = cv2.waitKey(10) & 0xFF norm = cross( sub(mytri.p2, mytri.p1), sub(mytri.p3, mytri.p1) ) mnorm = norm.mod() while(k != 27): img = np.zeros((res,res,3), np.uint8) n1 = add(mytri.p1,me.position) n2 = add(mytri.p2,me.position) n3 = add(mytri.p3,me.position) n1.project(me.ppdist) n2.project(me.ppdist) n3.project(me.ppdist) n1 = me.findfinal(n1)
import numpy as np from math import * import cv2 from point import * from light import light from player import player from surface import surface me = player() li = light() res = me.ppdist * 2 img = np.zeros((res, res, 3), np.uint8) mytri = surface('tri', point(0, 10, 0), point(10, 20, 0), point(0, 30, 10)) k = cv2.waitKey(10) & 0xFF norm = cross(sub(mytri.p2, mytri.p1), sub(mytri.p3, mytri.p1)) mnorm = norm.mod() while (k != 27): img = np.zeros((res, res, 3), np.uint8) n1 = add(mytri.p1, me.position) n2 = add(mytri.p2, me.position) n3 = add(mytri.p3, me.position) n1.project(me.ppdist) n2.project(me.ppdist) n3.project(me.ppdist) n1 = me.findfinal(n1)
rd_topcone_b = rdtopcone_rad / (rdtopcone_apex - rdtopcone_bot) rd_topcone_Q = np.vstack(([1, 0, 0], [0, 1, 0], [0, 0, -rd_topcone_b**2])) rd_topcone_P = np.array([0, 0, 2 * rd_topcone_b**2 * rdtopcone_apex]) rd_topcone_R = -(rd_topcone_b * rdtopcone_apex)**2 rd_botcone_b = rdbotcone_rad / (rdbotcone_apex - rdbotcone_bot) rd_botcone_Q = np.vstack(([1, 0, 0], [0, 1, 0], [0, 0, -rd_botcone_b**2])) rd_botcone_P = np.array([0, 0, 2 * rd_botcone_b**2 * rdbotcone_apex]) rd_botcone_R = -(rd_botcone_b * rdbotcone_apex)**2 surface_list = [] ## Inner Jar #inner_jar_density = -2.203 inner_jar_inner_cyl = surface.surface() inner_jar_inner_cyl.description = 'inside surface of inner quartz jar cylinder' inner_jar_inner_cyl.shape = 'cylinder' inner_jar_inner_cyl.param_list = [ np.array([0, 0, 0]), np.array([0, 0, 1]), r1[3] ] # shouldn't r be 10? inner_jar_inner_cyl.inbounds_function = lambda p: np.reshape( (p[:, 2, :] >= (ijar_elevation - ijar_cyllength)) * (p[:, 2, :] < ijar_elevation), (p.shape[0], -1)) # -66.40278, -21.61143 inner_jar_inner_cyl.n_outside = n_jar inner_jar_inner_cyl.n_inside = n_hydraulic inner_jar_inner_cyl.surface_type = 'normal' inner_jar_inner_cyl.absorption = 0 surface_list.append(inner_jar_inner_cyl) inner_jar_outer_cyl = surface.surface()