Example #1
0
 def test_advanced(self):
     x1 = 1
     y1 = 2
     p1 = Point(x1, y1)
     p2 = Point(x1 + 4, y1 + 4)
     p3 = Point(x1 + 4, y1)
     self.assertAlmostEqual(p3.distance(p1, p2), math.sqrt((2 ** 2) + (2 ** 2)), delta=eps)
     self.assertEqual(Point.orientation(p1, p2, p3), -1)
     self.assertEqual(Point.orientation(p1, p2, p1 + Point(1, 1)), 0)
Example #2
0
def get_bounds_k_simplified(triangle, unbound_point_index, coef):
    # XXX: copy-paste
    points = triangle.points
    sz = 6

    line_points = [Point.copy(points[(unbound_point_index + i + 1) % 3])
                   for i in range(2)]
    if unbound_point_index == 0:
        line_indices = [2, 3, 4]
    elif unbound_point_index == 1:
        line_indices = [0, 4, 5]
    elif unbound_point_index == 2:
        line_indices = [0, 1, 2]
    line_length = (line_points[1] - line_points[0]).length()
    
    psi_i = abc.i * (2 * abc.i - 1)
    psi_j = abc.j * (2 * abc.j - 1)
    psi_m = abc.m * (2 * abc.m - 1)

    psi_k = 4 * abc.i * abc.j
    psi_l = 4 * abc.j * abc.m
    psi_n = 4 * abc.i * abc.m

    arr = [psi_i, psi_k, psi_j, psi_l, psi_m, psi_n]

    ks_vector = np.zeros(sz, dtype=np.float64)
    
    for i in line_indices:
        sum_ = solve_phi_integrals(arr[i], True)
        ks_vector[i] = line_length * coef * sum_

    return ks_vector
Example #3
0
def get_bounds_k(triangle, unbound_point_index, coef):
    points = triangle.points
    sz = 6

    line_points = [Point.copy(points[(unbound_point_index + i + 1) % 3])
                   for i in range(2)]
    if unbound_point_index == 0:
        line_indices = [2, 3, 4]
    elif unbound_point_index == 1:
        line_indices = [0, 4, 5]
    elif unbound_point_index == 2:
        line_indices = [0, 1, 2]
    line_length = (line_points[1] - line_points[0]).length()

    # XXX: copy-paste
    psi_i = abc.i * (2 * abc.i - 1)
    psi_j = abc.j * (2 * abc.j - 1)
    psi_m = abc.m * (2 * abc.m - 1)

    psi_k = 4 * abc.i * abc.j
    psi_l = 4 * abc.j * abc.m
    psi_n = 4 * abc.i * abc.m

    arr = [psi_i, psi_k, psi_j, psi_l, psi_m, psi_n]

    k_matrix = np.zeros((sz, sz), dtype=np.float64)
    for i in line_indices:
        for j in line_indices:
            if j < i: continue
            polynome = arr[i] * arr[j]
            sum_ = solve_phi_integrals(polynome, True)
            k_matrix[i, j] = k_matrix[j, i] = coef * line_length * sum_
    
    return k_matrix
Example #4
0
    def split_indices(self, idx1, idx2):
        idx1 %= len(self.points)
        idx2 %= len(self.points)

        p1 = Point.copy(self.points[idx1])
        p2 = Point.copy(self.points[idx2])

        if idx2 < idx1:
            idx1, idx2 = idx2, idx1
            p1, p2 = p2, p1

        self.points.insert(idx1, p1)
        idx1 += 1
        idx2 += 1
        self.points.insert(idx2, p2)
        
        res = Polygon.copy(self.points[idx1:(idx2+1)])
        del self.points[idx1:(idx2+1)]
        return res
Example #5
0
    def process_case3(self, angle):
        l1 = Edge.length(self.curr_polygon.next(), self.curr_polygon.curr_point)
        l2 = Edge.length(self.curr_polygon.curr_point, self.curr_polygon.prev())

        p2 = self.curr_polygon.curr_point
        p1 = self.curr_polygon.prev()
        a = l2

        index = self.curr_polygon.curr_index

        if l1 < l2:
            p1 = self.curr_polygon.curr_point
            p2 = self.curr_polygon.next()
            a = l1
            index += 1

            p_middle = Point.new((p1.x + p2.x) / 2.0, (p1.y + p2.y) / 2.0)

        m = 2.0 * (p2.x - p1.x)
        n = 2.0 * (p2.y - p1.y)
        k = ((p2.x ** 2) + (p2.y ** 2)) - ((p1.x ** 2) + (p1.y ** 2))

        p = p2.y - p1.y
        q = p1.x - p2.x
        l = p1.x * p2.y - p2.x * p1.y + Math.sqrt(3.0) * a * a / 2.0

        det = n * p - q * m
        x_new = (l * n - k * q) / det
        y_new = (k * p - l * m) / det

        p = Point.new(x_new, y_new)

        if self.curr_polygon.has_point(p):
            return [p, index]

        # find symmetric point
        p_new = Point(2.0 * p.x - p_middle.x, 2.0 * p.y - p_middle.y)
        if p_new in self.curr_polygon:
            return [p_new, index]

        raise RuntimeError("doh doh doh 3")
Example #6
0
    def split(self, point):
        if not self.points:
            return None
        idx1 = self.curr_index
        idx2 = self.points.index(point)
        
        tmp_cur = Point.copy(self.curr_point)

        p1 = Point.copy(self.curr_point)
        p2 = Point.copy(point)

        if idx2 < idx1:
            idx1, idx2 = idx2, idx1
            p1, p2 = p2, p1

        self.points.insert(idx1, p1)

        poly2 = Polygon.copy(self.points[idx1:(idx2+1)]) # crude implementation of slice!
        del self.points[idx1:(idx2+1)]
        poly2.curr_point = tmp_cur
        self.curr_point = point

        return poly2
Example #7
0
    def __init__(self, conditions_list, diameter, subdivide_n=0):
        self.conditions = []
        self.points_to_condindex = {}
        self.diameter = diameter

        for key, value in conditions_list:
            p_start, p_end = key
            points = Edge.split(p_start, p_end, diameter)
            if points[-1] != p_end:
                points.append(Point.copy(p_end))

            self.conditions.append(ConditionsItem.copy(value))

            for i in range(len(points) - 1):
                p1_hash = hash(points[i])
                p2_hash = hash(points[i + 1])
                arr = tuple(sorted([p1_hash, p2_hash]))
                self.points_to_condindex[arr] = len(self.conditions) - 1
Example #8
0
def find_intruding_vertex(polygon):
    a = polygon.neighbor(sym.counterclockwise)
    b = polygon.curr_point
    c = polygon.advance(sym.clockwise)

    d = None
    bestD = -1.0
    ca = Edge(c, a)
    v = polygon.move_next()

    while v != a:
        if point_in_triangle(v, a, b, c):
            dist = v.distance(ca.origin, ca.destination)
            if dist > bestD:
                bestD = dist
                d = Point.copy(v)
        v = polygon.move_next()
    polygon.curr_point = b
    return d
Example #9
0
 def replace_point(self, point, new_point):
     i = self.points.index(point)
     self.points[i] = Point.copy(new_point)
Example #10
0
 def copy(points):
     res = Polygon()
     res.curr_index = 0
     for p in points:
         res.append(Point.copy(p))
     return res