def test_cartesian_distance(self): v1 = [1,0] v2 = [0,1] dist_1 = vector_utils.cartesian_distance_2d(v1, v2) dist_2 = math.sqrt((v1[0]-v2[0])**2+(v1[1]-v2[1])**2) self.assertEqual(dist_1, dist_2) v1 = [1,0] v2 = [0,0] dist_1 = vector_utils.cartesian_distance_2d(v1, v2) self.assertEqual(dist_1, 1) v1 = [1,0] v2 = [-1,0] dist_1 = vector_utils.cartesian_distance_2d(v1, v2) self.assertEqual(dist_1, 2)
def test_neighbour_distance(self): """ TODO: This test contains no asserts and has just been used as a way of eye-balling distances when debug is uncommented. Create a world with a fixed number of cells, where the expected approximate distance between neighbouring nodes is know, so aberrant configurations can be detected """ # Calculate min_dist # Create world total_cells=50 w = world.World(total_cells_desired=total_cells) starting_node = random.choice(w.all_boundary_nodes) for node in w.all_boundary_nodes: # Confirm node has neighbours self.assertGreater(len(starting_node.neighbours), 0) for neighbour in node.neighbours: #print("{0} to {1}".format(node.loc, neighbour.loc)) angular_dist = math.degrees(geographic_utils.radians_between_locations(node.loc, neighbour.loc)) node_cartesian_pos = geographic_utils.geographic_to_cartesian([np.array(node.loc)])[0] neighbour_cartesian_pos = geographic_utils.geographic_to_cartesian([np.array(neighbour.loc)])[0] direct_dist = vector_utils.cartesian_distance_2d(node_cartesian_pos, neighbour_cartesian_pos)
def geographic_direct_distance(a, b): """ Calculates direct distance between two coordinate locations, with a path that passes through the sphere """ cartesian_points = geographic_to_cartesian([a, b]) return cartesian_distance_2d(cartesian_points[0], cartesian_points[1])