Exemple #1
0
    def visibility(self, other, eps=EPS):
        I0 = self.base.project(other.base.source)
        I1 = self.base.project(other.base.target)

        divisor = point_distance(I0, I1)
        divisor = divisor if divisor > eps else eps

        midI = (I0 + I1) * 0.5
        return max(
            0, 1 - 2 * point_distance(self.base._mid_point, midI) / divisor)
Exemple #2
0
    def compute_divided_edge_length(self, edge_idx):
        length = 0.0

        for p0, p1 in sliding_window(2, self.subdivision_points[edge_idx]):
            length += point_distance(p0, p1)

        return length
Exemple #3
0
    def apply_electrostatic_force(self, edge_idx, i):
        sum_of_forces = np.array((0.0, 0.0))

        compatible_edges = self.compatible_edges[edge_idx]

        for oe in compatible_edges:
            force = (self.subdivision_points[oe][i] -
                     self.subdivision_points[edge_idx][i])

            if (math.fabs(force[0]) > self.eps) or (math.fabs(force[1]) >
                                                    self.eps):
                divisor = point_distance(self.subdivision_points[oe][i],
                                         self.subdivision_points[edge_idx][i])
                diff = 1 / divisor

                sum_of_forces += force * diff

        return sum_of_forces
Exemple #4
0
    def update_edge_divisions(self, P):
        for edge_idx in self.edges.keys():
            divided_edge_length = self.compute_divided_edge_length(edge_idx)
            segment_length = divided_edge_length / (P + 1)
            current_node = np.array(self.edges[edge_idx].base.source)
            new_subdivision_points = []
            number_subdiv_points = 0
            new_subdivision_points.append(np.array(current_node))
            # revisar que no se cambie si cambio el source
            number_subdiv_points += 1
            current_segment_length = segment_length
            i = 1
            finished = False
            while not finished:
                old_segment_length = point_distance(
                    self.subdivision_points[edge_idx][i], current_node)
                # direction is a vector of length = 1
                direction = (self.subdivision_points[edge_idx][i] -
                             current_node) / old_segment_length

                if current_segment_length > old_segment_length:
                    current_segment_length -= old_segment_length
                    current_node = np.array(
                        self.subdivision_points[edge_idx][i])
                    i += 1
                else:
                    current_node += current_segment_length * direction
                    new_subdivision_points.append(np.array(current_node))
                    number_subdiv_points += 1
                    current_segment_length = segment_length
                finished = number_subdiv_points == P + 1

            new_subdivision_points.append(
                np.array(self.edges[edge_idx].base.target))

            self.subdivision_points[edge_idx] = new_subdivision_points
Exemple #5
0
    def position_compatibility(self, other):
        lavg = (self.base.length() + other.base.length()) / 2.0
        midP = self.base._mid_point
        midQ = other.base._mid_point

        return lavg / (lavg + point_distance(midP, midQ))