def get_z_of_surface_and_plane(surface_: surface): cord1, cord2, cord3 = surface_.plane_cords[0] cord1 = Coordinate(*cord1) cord2 = Coordinate(*cord2) cord3 = Coordinate(*cord3) _, _, z = build_plane_by_three_coordinates(cord1, cord2, cord3, dots_count=surface_.dots_count) _, _, Z = surface_.xyz_grid return Z, z
def show_current_surface(surface, axes, plot, show=False): cord1, cord2, cord3 = surface.plane_cords[0] cord1 = Coordinate(*cord1) cord2 = Coordinate(*cord2) cord3 = Coordinate(*cord3) x, y, z = build_plane_by_three_coordinates(cord1, cord2, cord3, dots_count=surface.dots_count) X, Y, Z = surface.xyz_grid build_main_surface(axes, plot, X, Y, Z) build_surface(axes, x, y, z) if show: plot.show() return X, Y, Z
def generate_one_normal_surface_and_plane_for_it(): X, Y, Z = generate_main_surface() build_main_surface(AXES, PLOT, X, Y, Z) all_coordinates = get_all_coordinates_triplets(Z) all_possible_combinations = list(combinations( all_coordinates, 3)) # TODO: magic number remove # https://stackoverflow.com/questions/44355546/how-to-connect-points-in-python-ax-scatter-3d-plot # ЗАДАЧА СВОДИТСЯ К 2D normal_x = DOTS_COUNT / 2 normal_y = DOTS_COUNT / 2 normal_cords = Coordinate(x=normal_x, y=normal_y, z=0) # TODO: rename not_with_normal = filter_in_triangle_combinations( all_possible_combinations, normal_cords) in_triangle = filter_normal_coords_in_combinations(not_with_normal, normal_cords) square_build_cords = filter_is_not_stucked_plane(in_triangle, Z) # # TODO: построить вектор нормали # X = (0, 1, 1) # Y = (0, 1, 1) # Z1 = (normal_y, normal_y, 0) # Z2 = (normal_y, normal_y, 0) # ax.quiver(X, Y, Z1, X, Y, Z2, length=1, arrow_length_ratio=5) # plt.show() log_all_stuff(all_coordinates, all_possible_combinations, in_triangle, square_build_cords) if not square_build_cords: raise IndexError for num, plane_cords in enumerate(square_build_cords, start=1): cord1, cord2, cord3 = plane_cords print("%s) Три точки: %s %s %s" % (num, cord1, cord2, cord3)) # TODO: показать соединение точек x_plane, y_plane, z_plane = build_plane_by_three_coordinates( *plane_cords, dots_count=DOTS_COUNT) build_surface(AXES, x_plane, y_plane, z_plane) # TODO: отделить граф логику от расчета PLOT.show() return { "xyz_grid": (X, Y, Z), "plane_cords": [[cord1, cord2, cord3] for cord1, cord2, cord3 in square_build_cords], }
def get_all_coordinates_triplets(coordinates_array): """ Развёртка ndarray'я numpy в список tuple'ов (x,y,z) :param coordinates_array: numpy ndarray :return: list of named tuples """ coordinates = [] for index, zn in np.ndenumerate(coordinates_array): yn, xn = index coordinates.append(Coordinate(xn, yn, zn)) return coordinates
class GapFinderTestCase(TestCase): cord1 = Coordinate(x=0, y=0, z=1) cord2 = Coordinate(x=0, y=1, z=1) cord3 = Coordinate(x=2, y=0, z=0) cords = [cord1, cord2, cord3] normal_in_triangle = Coordinate(x=1, y=0) normal_not_in_triangle = Coordinate(x=10, y=0) def test_triangle_square(self): zero_square = get_triangle_square_from_three_cords( self.cord1, self.cord1, self.cord1) self.assertEqual(zero_square, 0) square = get_triangle_square_from_three_cords(self.cord1, self.cord2, self.cord3) self.assertEqual(square, 1) def test_dot_in_triangle(self): is_dot_in = is_dot_in_triangle(self.cords, self.normal_in_triangle) self.assertEqual(is_dot_in, True) is_dot_in = is_dot_in_triangle(self.cords, self.normal_not_in_triangle) self.assertEqual(is_dot_in, False) def test_plane_generation(self): x, y, z = build_plane_by_three_coordinates(*self.cords, dots_count=DOTS_COUNT) build_surface(AXES, x, y, z) # TODO: описать в документации # z[y coordinate ][ x coordinate] self.assertEqual(z[0][0], self.cord1.z) self.assertEqual(z[1][0], self.cord2.z) self.assertEqual(z[0][2], self.cord3.z) PLOT.show()
sum([pow(a1, 2), pow(b1, 2), pow(c1, 2), pow(d1, 2)])) sqrt_sum_2 = math.sqrt( sum([pow(a2, 2), pow(b2, 2), pow(c2, 2), pow(d2, 2)])) print(sqrt_sum_1, sqrt_sum_2) sum_multiplication = abs(a1 * a2 + b1 * b2 + c1 * c2) cos_alpha = sum_multiplication / (sqrt_sum_1 * sqrt_sum_2) return cos_alpha if __name__ == '__main__': engine = get_engine(**DB_SETTINGS) service = SurfaceService(engine) surface = service.get_surfaces(limit=1)[0] # show_current_surface(surface, AXES, PLOT, show=True) # cord1, cord2, cord3 = cord1 = Coordinate(x=0, y=0, z=1) cord2 = Coordinate(x=2, y=2, z=1) cord3 = Coordinate(x=3, y=3, z=1) # TODO: не работает! s = find_angle_between_two_planes((cord1, cord2, cord3), surface.plane_cords[0]) print(s)