def test_are_equal(self): self.assertTrue( Plane(Vector([-0.412, 3.806, 0.728]), -3.46).are_equal(Plane(Vector([1.03, -9.515, -1.82]), 8.65))) self.assertFalse( Plane(Vector([2.611, 5.528, 0.283]), 4.6).are_equal(Plane(Vector([7.715, 8.306, 5.342]), 3.76)))
def get_plane(self): #TODO: MUDAR A FORMA DE OBTENÇÃO DOS AVIÕES self.id_flight = [ 'LA 2203', 'GZ 0331', 'AZ 0032', 'AZ 0157', 'GZ 0667' ] self.airplane_routes = self.utils.transform_data_file( self.utils.read_csv(self.table)) for time in range(0, 151, 10): for flight in self.id_flight: self.data_flight = self.airplane_routes.get( (str(time), flight)) if int(self.data_flight[5]) != 0: self.airplane = Plane( int(self.data_flight[5]) + 250, int(float(self.data_flight[6])) + 250, int(self.data_flight[7])) if int(self.data_flight[5]) == 0: self.airplane = Plane(int(self.data_flight[5]), int(float(self.data_flight[6])), int(self.data_flight[7])) self.airplane.draw_plane(self.draw, self.data_flight) tm.sleep(2) self.reset() print('acabei o loop')
def test_linsys_swap_row(): """Test Linear System Swap Row""" plane_1 = Plane(Vector([1, 1, 1]), 1) plane_2 = Plane(Vector([0, 1, 0]), 2) plane_3 = Plane(Vector([1, 1, -1]), 3) plane_4 = Plane(Vector([1, 0, -2]), 2) lin_sys = LinearSystem([plane_1, plane_2, plane_3, plane_4]) lin_sys.swap_rows(0, 1) assert lin_sys[0] == plane_2 # swapped assert lin_sys[1] == plane_1 # swapped assert lin_sys[2] == plane_3 assert lin_sys[3] == plane_4 lin_sys.swap_rows(1, 3) assert lin_sys[0] == plane_2 assert lin_sys[1] == plane_4 # swapped assert lin_sys[2] == plane_3 assert lin_sys[3] == plane_1 # swapped lin_sys.swap_rows(3, 1) assert lin_sys[0] == plane_2 assert lin_sys[1] == plane_1 # swapped assert lin_sys[2] == plane_3 assert lin_sys[3] == plane_4 # swapped
def add_multiple_times_row_to_row(self, coefficient, row_to_add, row_to_be_added_to): p = Plane(self.planes[row_to_add].normal_vector, self.planes[row_to_add].constant_term) p.normal_vector = p.normal_vector * coefficient p.constant_term *= coefficient self.planes[row_to_be_added_to] = Plane( self.planes[row_to_be_added_to].normal_vector + p.normal_vector, self.planes[row_to_be_added_to].constant_term + p.constant_term)
def __init__(self, fovy, ratio, near, far, robot_files): self.fovy = fovy self.near = near self.far = far self.ratio = ratio self.camera = None self.plane = Plane((2, 2)) self.wall = Plane((20, 10)) self.mw = tr.rotation_matrix(-m.pi / 2.0, (1, 0, 0)) self.mw = np.dot(self.mw, tr.translation_matrix((0, 3, 0))) self.robot = Robot(robot_files) self.x = 0.0 self.last_time = timer() self.plane_alpha = 65.0 / 180.0 * m.pi self.lpos = [1, -1, 0] self._make_plane_matrix() self.draw_robot = True self.draw_sparks = True self.draw_front = False self.draw_back = False
def test_plane_is_parallel(): """Test if a plane is parallel""" plane1 = Plane(Vector([2, 3, 4]), 6) plane2 = Plane(Vector([2, 3, 4]), 1) assert plane1.is_parallel(plane2) is True assert plane1.is_coincidence(plane2) is False
def __init__(self, source_path=None, save_path='/home/pi/Desktop/Rhapsody-of-nonsense/records/', save=1, debug=0): """debug: manual read video (" ", "x"), and no use PIGPIO""" self.debug = debug self.frame_queue = Queue(1) self.feedback_queue = Queue() self.record = Record(self.frame_queue, debug=self.debug, feedback_queue=self.feedback_queue, source_path=source_path, save=save, save_path=save_path) self.source_path = source_path self.frame_new = None self.c = C_START self._stop = 0 self.box = Box() self.light_color = 0 self.color = 'r' self.need_drop = False self.dropped = False if not debug: try: self.plane = Plane() except: display('Error: Failed to connect plane') raise IOError elif __name__ == '__main__': self.plane = Plane(debug=1)
def test_rref_1(): p1 = Plane(normal_vector=Vector(['1', '1', '1']), constant_term='1') p2 = Plane(normal_vector=Vector(['0', '1', '1']), constant_term='2') s = LinearSystem([p1, p2]) r = s.compute_rref() assert (r[0] == Plane(normal_vector=Vector(['1', '0', '0']), constant_term='-1') and r[1] == p2)
def add_multiple_times_row_to_row(self, ratio, row_to_add, row_to_added_to): """ 实现方程组中将某一行乘以一定倍数后加到某一行上的操作 Args: ratio -- 要乘以的系数 row_to_add -- 加到另一行上的方程,也就是被乘的那个 row_to_added_to -- 被加的那一行 Raises: IndexOutOfBounds -- 处理这个函数中可能出现的角标越界异常 """ row_to_add_plane = Plane( Vector([ self.planes[row_to_add].a * ratio, self.planes[row_to_add].b * ratio, self.planes[row_to_add].c * ratio ]), self.planes[row_to_add].k * ratio) self.planes[row_to_added_to] = Plane( Vector([ self.planes[row_to_added_to].a + row_to_add_plane.a, self.planes[row_to_added_to].b + row_to_add_plane.b, self.planes[row_to_added_to].c + row_to_add_plane.c ]), self.planes[row_to_added_to].k + row_to_add_plane.k)
def test_triangular_1_1(): p1 = Plane(normal_vector=Vector(['0', '0', '3']), constant_term='3') p2 = Plane(normal_vector=Vector(['0', '2', '2']), constant_term='2') p3 = Plane(normal_vector=Vector(['1', '1', '1']), constant_term='1') s = LinearSystem([p1, p2, p3]) t = s.compute_triangular_form() assert (t[0] == p3 and t[1] == p2 and t[2] == p1)
def init_planes(self) -> list: '''initialize four planes''' plane1 = Plane(self.color,1) plane2 = Plane(self.color,2) plane3 = Plane(self.color,3) plane4 = Plane(self.color,4) return [plane1,plane2,plane3,plane4]
def __init__(self, h): nz = cos(radians(h)) nx = sqrt(1 - nz * nz) height = nz / nx #print(nx, nz, height) self.lside = Plane(Vec3(0.0, 0.0, -height), Vec3(nx, 0.0, nz)) self.rside = Plane(Vec3(0.0, 0.0, -height), Vec3(-nx, 0.0, nz))
def test_is_parallel2(self): # plane 1: 2.611x + 5.528y + 0.283z = 4.6 # plane 2: 7.715x + 8.306y + 5.342z = 3.76 plane1 = Plane(Vector([2.611, 5.528, 0.283]), 4.6) plane2 = Plane(Vector([7.715, 8.306, 5.342]), 3.76) result = plane1.is_parallel(plane2) self.assertFalse(result)
def test_is_equal3(self): # plane 1: -7.926x + 8.625y - 7.217 z = -7.952 # plane 2: -2.642x + 2.875y - 2.404z = -2.443 plane1 = Plane(Vector([-7.926, 8.625, -7.217]), -7.952) plane2 = Plane(Vector([-2.642, 2.875, -2.404]), -2.443) result = plane1 == plane2 self.assertFalse(result)
def test_is_equal(self): # plane 1: -0.412x + 3.806y + 0.728z = -3.46 # plane 2: 1.03x + 9.515y - 1.82z = 8.65 plane1 = Plane(Vector([-0.412, 3.806, 0.728]), -3.46) plane2 = Plane(Vector([1.03, 9.515, -1.82]), 8.65) result = plane1 == plane2 self.assertTrue(result)
def test_case_1(): p0 = Plane(normal_vector=Vector(['1', '1', '1']), constant_term='1') p1 = Plane(normal_vector=Vector(['0', '1', '0']), constant_term='2') p2 = Plane(normal_vector=Vector(['1', '1', '-1']), constant_term='3') p3 = Plane(normal_vector=Vector(['1', '0', '-2']), constant_term='2') s = LinearSystem([p0, p1, p2, p3]) s.swap_rows(0, 1) assert (s[0] == p1 and s[1] == p0 and s[2] == p2 and s[3] == p3)
def create_planes(self): """ Create airplanes """ self.planes.append(Plane("Boeing 777", 600, 17395)) self.planes.append(Plane("Airbus A380", 643, 16670)) self.planes.append(Plane("Boeing 787", 710, 15750)) self.planes.append(Plane(" Boeing 747-8i", 850, 13750))
def test_plane_is_coincidence_scale(): """Test if a plane is a coincidece""" plane1 = Plane(Vector([2, 3, 4]), 1) plane2 = Plane(Vector([4, 6, 8]), 2) assert plane1.is_parallel(plane2) is True assert plane1.is_coincidence(plane2) is True assert plane1.plane_relationship(plane2) == 'planes are coincidental'
def test_is_parallel3(self): # plane 1: -7.926x + 8.625y - 7.217 z = -7.952 # plane 2: -2.642x + 2.875y - 2.404z = -2.443 plane1 = Plane(Vector([-7.926, 8.625, -7.212]), -7.952) plane2 = Plane(Vector([-2.642, 2.875, -2.404]), -2.443) result = plane1.is_parallel(plane2) self.assertTrue(result)
def test_is_parallel(self): # plane 1: -0.412x + 3.806y + 0.728z = -3.46 # plane 2: 1.03x + 9.515y - 1.82z = 8.65 plane1 = Plane(Vector([-0.412, 3.806, 0.728]), -3.46) plane2 = Plane(Vector([1.03, 9.515, -1.82]), 8.65) result = plane1.is_parallel(plane2) self.assertFalse(result)
def multiply_coefficient_and_row(self, coefficient, row): #行号不能超过方程的总数,否则就会 index 溢出 assert row < self.len new_normal_vector = self[row].normal_vector.multiply(coefficient) new_constant_term = Decimal( self[row].constant_term) * Decimal(coefficient) self[row] = Plane(new_normal_vector, new_constant_term) return Plane(new_normal_vector, new_constant_term)
def test_infinite_solutions(): """Test the system has infinite solutions""" plane_4 = Plane(Vector([1, 1, 1]), 3) plane_5 = Plane(Vector([2, 4, 1]), 8) plane_6 = Plane(Vector([6, 10, 4]), 22) lin_sys_2 = LinearSystem([plane_4, plane_5, plane_6]) solutions_2 = lin_sys_2.system_solutions() assert solutions_2 == 'system has infinite solutions'
def add_multiple_times_row_to_row(self, coefficient, row_to_add, row_to_be_added_to): plane_times_coef = Plane(self[row_to_add].normal_vector * coefficient, self[row_to_add].constant_term * coefficient) new_normal = self[ row_to_be_added_to].normal_vector + plane_times_coef.normal_vector new_constant = self[ row_to_be_added_to].constant_term + plane_times_coef.constant_term self[row_to_be_added_to] = Plane(new_normal, new_constant)
def test_dictionary_not_ok(self): test_plane1 = Plane("NYC", "LA") test_plane2 = Plane("NYC", "LA") test_plane3 = Plane("NYC", "LA") env = Environment() env.add_plane(test_plane1, "plane1") env.add_plane(test_plane2, "plane2") env.add_plane(test_plane3, "plane2") self.assertFalse(len(env.planes) == 3)
def track(fixed_points: List[Tuple[float, float]], lat_min: float, lat_max: float, long_min: float, long_max: float, r: float = 25.): """ :param fixed_points: list of fixed points to display. first item is tracking centre :param r: range (km) of tracking, from centre :param lat_min: minimum latitude to use for display grid :param lat_max: maximum latitude to use for display grid :param long_min: minimum longitude to use for display grid :param long_max: maximum longitude to use for display grid :return: None """ lat, long = x_low + (x_high - x_low) / 2, y_low + (y_high - y_low) / 2 print("getting data...") print(lat, long, r) url = "https://public-api.adsbexchange.com/VirtualRadar/AircraftList.json?lat={}&lng={}&fDstL=0&fDstU={}".format( lat, long, r) current_ac = {} # add fixed point(s) for i, (x, y) in enumerate(fixed_points): current_ac["fixed" + str(i)] = Plane("fixed" + str(i), {"lat": x, "long": y, "kLat": x, "kLong": y, # for k_filter "alt": 0, "type": "static"}) while True: try: r = requests.get(url, headers={"User-Agent": "Mozilla/5.0"}) assert r.ok data = json.loads(r.text) aclist = [{k.lower(): v for k, v in ac.items()} for ac in data["acList"]] except: print("{}: connection error.".format(datetime.strftime(datetime.now(), "%H:%M:%S"))) time.sleep(2) continue for ac in aclist: reg = ac.get("reg") core_data = Plane.extract_data(ac) print(core_data) if reg: plane = current_ac.get(reg) if plane: plane.update_fields(core_data) else: plane = Plane(reg, core_data) current_ac[reg] = plane display_to_console(current_ac) current_ac = purge(current_ac) grid = make_grid(current_ac, lat_min, lat_max, long_min, long_max) plot(grid) log(current_ac) time.sleep(2)
def test_add_planes(): """Test Adding two Planes""" plane_1 = Plane(Vector([1, 2, 3]), 4) plane_2 = Plane(Vector([-1, 7, 3]), 1) plane_3 = plane_1 + plane_2 answer = Plane(Vector([0, 9, 6]), 5) assert plane_3 == answer
def test_single_solution(): """Test the system has a single solution""" plane_7 = Plane(Vector([1, 1, 1]), 1) plane_8 = Plane(Vector([0, 1, 0]), 2) plane_9 = Plane(Vector([1, 1, -1]), 3) plane_10 = Plane(Vector([1, 0, -2]), 2) lin_sys_3 = LinearSystem([plane_7, plane_8, plane_9, plane_10]) solutions_3 = lin_sys_3.system_solutions() assert solutions_3 == 'solution is: a = 0.000, b = 2.000, c = -1.000'
def test_no_consistent_solutions(): """Test the system has no solutions""" plane_1 = Plane(Vector([1, 1, -1]), 2) plane_2 = Plane(Vector([2, 3, -1]), 0) plane_3 = Plane(Vector([3, 4, -2]), 1) lin_sys_1 = LinearSystem([plane_1, plane_2, plane_3]) solutions_1 = lin_sys_1.system_solutions() assert solutions_1 == 'system has no consistent solutions'
def test_ge_solution(): """Quiz 12 Coding Gaussian Elimination""" plane_1 = Plane(Vector([5.862, 1.178, -10.366]), -8.15) plane_2 = Plane(Vector([-2.931, -0.589, 5.183]), -4.075) lin_sys_1 = LinearSystem([plane_1, plane_2]) solutions_1 = lin_sys_1.system_solutions() assert solutions_1 == 'system has no consistent solutions' plane_3 = Plane(Vector([8.631, 5.112, -1.816]), 5.113) plane_4 = Plane(Vector([4.315, 11.132, 5.27]), 6.775) plane_5 = Plane(Vector([-2.158, 3.01, -1.727]), -0.831) lin_sys_2 = LinearSystem([plane_3, plane_4, plane_5]) solutions_2 = lin_sys_2.system_solutions() assert solutions_2 == 'system has infinite solutions' plane_6 = Plane(Vector([5.262, 2.739, -9.878]), -3.441) plane_7 = Plane(Vector([5.111, 6.358, 7.638]), -2.152) plane_8 = Plane(Vector([2.016, -9.924, -1.367]), -9.278) plane_9 = Plane(Vector([2.167, -13.543, -18.883]), -10.567) lin_sys_3 = LinearSystem([plane_6, plane_7, plane_8, plane_9]) solutions_3 = lin_sys_3.system_solutions() assert solutions_3 == 'solution is: a = -1.177, b = 0.707, c = -0.083'
def test_parametrization(self): p1 = Plane(normal_vector=Vector([0.786, 0.786, 0.588]), constant_term=-0.714) p2 = Plane(normal_vector=Vector([-0.131, -0.131, 0.244]), constant_term=0.319) s = LinearSystem([p1, p2]) solution = s.compute_solution() self.assertEqual(solution.basepoint, Vector(['-1.346', '0', '0.585'])) self.assertEqual(len(solution.direction_vectors), 1) self.assertEqual(solution.direction_vectors[0], Vector(['-1.0', '1.0', '0'])) p1 = Plane(Vector([8.631, 5.112, -1.816]), -5.113) p2 = Plane(Vector([4.315, 11.132, -5.27]), -6.775) p3 = Plane(Vector([-2.158, 3.01, -1.727]), -0.831) s = LinearSystem([p1, p2, p3]) solution = s.compute_solution() self.assertEqual(solution.basepoint, Vector(['-0.301', '-0.492', '0'])) self.assertEqual(len(solution.direction_vectors), 1) self.assertEqual(solution.direction_vectors[0], Vector(['-0.091', '0.509', '1.0'])) p1 = Plane(Vector([0.935, 1.76, -9.365]), -9.955) p2 = Plane(Vector([0.187, 0.352, -1.873]), -1.991) p3 = Plane(Vector([0.374, 0.704, -3.746]), -3.982) p4 = Plane(Vector([-0.561, -1.056, 5.619]), 5.973) s = LinearSystem([p1, p2, p3, p4]) solution = s.compute_solution() self.assertEqual(solution.basepoint, Vector(['-10.647', '0', '0'])) self.assertEqual(len(solution.direction_vectors), 2) self.assertEqual(solution.direction_vectors[0], Vector(['-1.882', '1.0', '0'])) self.assertEqual(solution.direction_vectors[1], Vector(['10.016', '0', '1.0']))