def parse(model: str) -> {}: with open( str(get_project_root()) + '/configs/' + model + '_input.json', 'r') as input_file: data = input_file.read() configs = json.loads(data) return { 'start_laser_location': Point3d(configs['laser_loc'][0], configs['laser_loc'][1], configs['laser_loc'][2]), 'start_laser_direction': Vector( Point3d(configs['laser_dir'][0], configs['laser_dir'][1], configs['laser_dir'][2])), 'down_triangle': [ Point3d(configs['down_tr'][0][0], configs['down_tr'][0][1], configs['down_tr'][0][2]), Point3d(configs['down_tr'][1][0], configs['down_tr'][1][1], configs['down_tr'][1][2]), Point3d(configs['down_tr'][2][0], configs['down_tr'][2][1], configs['down_tr'][2][2]), ], 'up_triangle': [ Point3d(configs['up_triangle'][0][0], configs['up_triangle'][0][1], configs['up_triangle'][0][2]), Point3d(configs['up_triangle'][1][0], configs['up_triangle'][1][1], configs['up_triangle'][1][2]), Point3d(configs['up_triangle'][2][0], configs['up_triangle'][2][1], configs['up_triangle'][2][2]), ], "target_radius": configs["target_radius"] }
def __init__(self, mirror: Mirror): self.mirror = mirror # Init points and their coordinates. point_a, point_b, point_c = mirror.triangle.get_points() side_ab = self.calculate_side_length(point_b, point_c) side_bc = self.calculate_side_length(point_a, point_c) side_ca = self.calculate_side_length(point_a, point_b) self.inradius = self.get_inradius(side_ab, side_bc, side_ca) # median_a, median_b, median_c = self.get_medians(side_ab, side_bc, side_ca) self.centroid: Point3d = Point3d(0.417, 0.417, 0)
def run(): pygame.init() config = parser.parse('2d') periscope = Periscope(config) renderer = Renderer(periscope) p_target = periscope.ray_to_aim().intersect_plane( Triangle(Point3d(0.2, 0.5, 0.2), Point3d(0.2, 0.4, 0.1), Point3d(0.2, 0.3, 0.5))) tee = Target(p_target, config["target_radius"]) periscope.set_target(tee) iteration = 0 while True: for i in pygame.event.get(): if i.type == pygame.QUIT: exit() elif i.type == pygame.KEYDOWN: if i.key == pygame.K_UP: tee.location.y += 0.01 elif i.key == pygame.K_DOWN: tee.location.y -= 0.01 elif i.key == pygame.K_RIGHT: tee.location.x += 0.01 elif i.key == pygame.K_LEFT: tee.location.x -= 0.01 elif i.key == pygame.K_KP2: tee.location.z -= 0.01 elif i.key == pygame.K_KP1: tee.location.z += 0.01 DirectAlgorithm.correct_planes(periscope, iteration) iteration += 1 mirror_down = periscope.mirror_down mirror_up = periscope.mirror_up p1_intersect = periscope.laser.intersect_plane(mirror_down.triangle) p2_intersect = periscope.laser.reflect_plane( mirror_down.triangle).intersect_plane(mirror_up.triangle) p_aim = periscope.ray_to_aim().intersect_plane( Triangle(Point3d(tee.location.x, 0.5, 0.2), Point3d(tee.location.x, 0.4, 0.1), Point3d(tee.location.x, 0.3, 0.5))) renderer.render(p1_intersect, p2_intersect, tee, p_aim) pygame.time.delay(10)
def final_ray_target_diff(laser: Ray, down_plane: Triangle, up_plane: Triangle, target: Point3d) -> float: ray_to_target = laser.reflect_plane(down_plane).reflect_plane(up_plane) return target.distance_to_line( ray_to_target.startPos, ray_to_target.startPos + ray_to_target.dir)