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
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
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
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
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
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
def replace_point(self, point, new_point): i = self.points.index(point) self.points[i] = Point.copy(new_point)
def copy(points): res = Polygon() res.curr_index = 0 for p in points: res.append(Point.copy(p)) return res