Exemplo n.º 1
0
    def __curve(self, dots_for_curve: list, q: int):
        dots_inside = dots_for_curve[1:-1]

        try:
            normal_x, normal_y = -q / (dots_for_curve[0][0] - dots_for_curve[-1][0]), \
                     q / (dots_for_curve[0][1] - dots_for_curve[-1][1])
        except ZeroDivisionError:
            return dots_for_curve

        normal_vector_length = sqrt(normal_x**2 + normal_y**2)

        dots_curved = []

        f_dist = function_for_curve_distance_generator(
            dist(dots_for_curve[0], dots_for_curve[-1]))

        for x in dots_inside:
            dist_coefficient = f_dist(dist(dots_for_curve[0], x))
            distance = self.config[CURVE_DISTANCE] * dist_coefficient

            dot_new = (x[0] + distance / normal_vector_length * normal_x,
                       x[1] + distance / normal_vector_length * normal_y)

            dots_curved.append(dot_new)

        dots_curved = [dots_for_curve[0]] + dots_curved + [dots_for_curve[-1]]

        return dots_curved
Exemplo n.º 2
0
    def __find_further_dot(self):
        dot_further = (0, 0, 100000)

        dot_max, dist_max = self.dots[0], dist(self.dots[0], dot_further)
        for dot in self.dots[1:]:
            dist_current = dist(dot, dot_further)

            if dist_current > dist_max:
                dot_max = dot
                dist_max = dist_current

        return dot_max
Exemplo n.º 3
0
    def paint(self, paint_obj):
        super().paint(paint_obj)

        dots = [
            list(dots)
            for dots in list(itertools.combinations(self.dots_projected, 2))
        ]
        for x in dots:
            if dist(x[0], x[1]) < 20:
                self.ok = False

        if paint_obj is None:
            return

        self._draw_line(self.dots[0], self.dots[1],
                        self._is_line_is_dot(self.dots[0], self.dots[1]))
        self._draw_line(self.dots[0], self.dots[3],
                        self._is_line_is_dot(self.dots[0], self.dots[3]))

        self._draw_line(self.dots[1], self.dots[2],
                        self._is_line_is_dot(self.dots[1], self.dots[2]))
        self._draw_line(self.dots[1], self.dots[3],
                        self._is_line_is_dot(self.dots[1], self.dots[3]))

        self._draw_line(self.dots[2], self.dots[0],
                        self._is_line_is_dot(self.dots[2], self.dots[0]))
        self._draw_line(self.dots[2], self.dots[3],
                        self._is_line_is_dot(self.dots[2], self.dots[3]))
Exemplo n.º 4
0
    def paint(self, paint_obj):
        def paint_lines(start, end, step=0):
            for i in range(start, end):
                a, b = self.dots[i], self.dots[i + 1 + step]
                self._draw_line(a, b, self._is_line_is_dot(a, b))

        super().paint(paint_obj)

        if paint_obj is None:
            return

        from library.helpers import dist

        dots = [
            list(dots)
            for dots in list(itertools.combinations(self.dots_projected, 2))
        ]
        for x in dots:
            if dist(x[0], x[1]) < 20:
                self.ok = False

        paint_lines(0, 3)
        self._draw_line(self.dots[0], self.dots[3],
                        self._is_line_is_dot(self.dots[0], self.dots[3]))

        paint_lines(4, 7)
        self._draw_line(self.dots[4], self.dots[7],
                        self._is_line_is_dot(self.dots[4], self.dots[7]))

        paint_lines(0, 4, 3)
Exemplo n.º 5
0
    def _is_line_is_dot(self, a, b) -> bool:
        if self.further_dot is None:
            raise FurtherDotMissed

        triangle_dots = [
            list(dots)
            for dots in list(itertools.combinations(self.dots_projected, 3))
        ]

        inside = False
        dot_inside = []

        for dots in triangle_dots:
            dot_check = [
                dot for dot in self.dots_projected if dot not in dots
            ][0]
            if is_dot_inside_triangle(dot_check, dots):
                inside = True
                dot_inside = self.dots[self.dots_projected.index(dot_check)]
                break

        if inside:
            dots_on_plane = [dot for dot in self.dots if not dot == dot_inside]

            dot_on_plane = [(dots_on_plane[0][0] + dots_on_plane[1][0] +
                             dots_on_plane[2][0]) / 3,
                            (dots_on_plane[0][1] + dots_on_plane[1][1] +
                             dots_on_plane[2][1]) / 3,
                            (dots_on_plane[0][2] + dots_on_plane[1][2] +
                             dots_on_plane[2][2]) / 3]
            distant_dot = [0, 0, 10000000]

            dist_to_plane = dist(distant_dot, dot_on_plane)
            dist_to_further_dot = dist(dot_inside, distant_dot)

            if dist_to_further_dot > dist_to_plane:
                if list(a) == dot_inside or list(b) == dot_inside:
                    return True

        else:
            triangle_dots = [
                dot for dot in self.dots_projected
                if not dot == self.further_dot_projected
            ]

            triangle_dots_pairs = [
                list(dots)
                for dots in itertools.combinations(triangle_dots, 2)
            ]

            angles = [
                angle(self.further_dot_projected, dots)
                for dots in triangle_dots_pairs
            ]
            angle_max = max(angles)

            dots_can_see = triangle_dots_pairs[angles.index(angle_max)]

            for dot in triangle_dots:
                if dot in dots_can_see:
                    continue

                if ([a[0], a[1]] == dot and [b[0], b[1]] == self.further_dot_projected) or \
                        ([a[0], a[1]] == self.further_dot_projected and [b[0], b[1]] == dot):
                    return True

        return False