def get_3d(self, cell, numribs=0, midribs=None, with_numpy=False): """ Get 3d-Panel :param glider: glider class :param numribs: number of miniribs to calculate :return: List of rib-pieces (Vectorlist) """ xvalues = cell.rib1.profile_2d.x_values ribs = [] for i in range(numribs + 1): y = i / numribs if midribs is None: midrib = cell.midrib(y, with_numpy) else: midrib = midribs[i] x1 = self.cut_front["left"] + y * (self.cut_front["right"] - self.cut_front["left"]) front = get_x_value(xvalues, x1) x2 = self.cut_back["left"] + y * (self.cut_back["right"] - self.cut_back["left"]) back = get_x_value(xvalues, x2) ribs.append(midrib.get(front, back)) # todo: return polygon-data return ribs
def get_3d(self, glider, numribs=0): """ Get 3d-Panel :param glider: glider class :param numribs: number of miniribs to calculate :return: List of rib-pieces (Vectorlist) """ cell = glider.cells[self.cell_no] xvalues = glider.x_values numribs += 1 ribs = [] for i in range(numribs): y = i / numribs front = get_x_value(xvalues, self.l_1 + y * (self.l_1 - self.r_1)) back = get_x_value(xvalues, self.l_2 + y * (self.l_2 - self.r_2)) ribs.append(cell.midrib(y).get(front, back)) # todo: return polygon-data return ribs
def get_3d(self, glider, numribs=0): """ Get 3d-Panel :param glider: glider class :param numribs: number of miniribs to calculate :return: List of rib-pieces (Vectorlist) """ cell = glider.cells[self.cell_no] xvalues = glider.x_values numribs += 1 ribs = [] for i in range(numribs): y = i / numribs front = get_x_value(xvalues, self.l_1 + y * (self.l_1 - self.r_1)) back = get_x_value(xvalues, self.l_2 + y * (self.l_2 - self.r_2)) ribs.append(cell.midrib(y).get(front, back)) # todo: return polygon-data return ribs
def _get_inner_outer(self, x_value): ik = get_x_value(self.x_values, x_value) #ik = get_x_value(self.x_values, position) inner = self.inner[ik] outer = inner + PolyLine2D( self.inner).get_normal(ik) * self.config.allowance_general #inner = self.inner[ik] # outer = self.outer[ik] return inner, outer
def _get_ik_values(self, cell, numribs=0): """ :param cell: the parent cell of the panel :param numribs: number of interpolation steps between ribs :return: [[front_ik_0, back_ik_0], ...[front_ik_n, back_ik_n]] with n is numribs + 1 """ x_values = cell.rib1.profile_2d.x_values ik_values = [ [get_x_value(x_values, self.cut_front["left"]), get_x_value(x_values, self.cut_back["left"])] ] for i in range(numribs): y = float(i+1)/(numribs+1) x_front = self.cut_front["left"] + y * (self.cut_front["right"] - self.cut_front["left"]) x_back = self.cut_back["left"] + y * (self.cut_back["right"] - self.cut_back["left"]) front = get_x_value(x_values, x_front) back = get_x_value(x_values, x_back) ik_values.append([front, back]) ik_values.append( [get_x_value(x_values, self.cut_front["right"]), get_x_value(x_values, self.cut_back["right"])] ) return ik_values
def _insert_text(self, plotpart): if self.config.layout_seperate_panels and not self.panel.is_lower(): left = get_x_value(self.x_values, self.panel.cut_back["left"]) right = get_x_value(self.x_values, self.panel.cut_back["right"]) p2 = self.ballooned[1][right] p1 = self.ballooned[0][left] align = "left" else: left = get_x_value(self.x_values, self.panel.cut_front["left"]) right = get_x_value(self.x_values, self.panel.cut_front["right"]) p1 = self.ballooned[1][right] p2 = self.ballooned[0][left] align = "right" text = self.panel.name part_text = Text(text, p1, p2, size=self.config.allowance_design * 0.8, align=align, valign=0.6, height=0.8).get_vectors() plotpart.layers["text"] += part_text
def _insert_center_rods(self, plotpart): start = -0.15 end = 0.15 front = (self.panel.cut_front["left"] + self.panel.cut_front["right"]) / 2 back = (self.panel.cut_back["left"] + self.panel.cut_back["right"]) / 2 if end < min(self.panel.cut_front["left"], self.panel.cut_front["right"]): return elif start > max(self.panel.cut_back["left"], self.panel.cut_back["right"]): return k_start = get_x_value(self.x_values, start) k_end = get_x_value(self.x_values, end) middle_line = self._get_middle_line(0.5) curve_left = self.ballooned[0] curve_right = self.ballooned[1] # cut with front and back front_left = curve_left[get_x_value(self.x_values, self.panel.cut_front["left"])] front_right = curve_right[get_x_value(self.x_values, self.panel.cut_front["right"])] back_left = curve_left[get_x_value(self.x_values, self.panel.cut_back["left"])] back_right = curve_right[get_x_value(self.x_values, self.panel.cut_back["right"])] cut_fronts = middle_line.cut(front_left, front_right, startpoint=k_start, extrapolate=True) cut_backs = middle_line.cut(back_left, back_right, startpoint=k_end, extrapolate=True) cut_front = next(cut_fronts)[0] cut_back = next(cut_backs)[0] k_front = max(k_start, cut_front) k_back = min(k_end, cut_back) #print(cut_front, k_front, cut_back, k_back, self.panel.cut_front, self.panel.cut_back) if k_back > k_front: plotpart.layers["marks"] += [middle_line[k_front:k_back]] if front < start < back: k_start = get_x_value(self.x_values, start) plotpart.layers["L0"].append(PolyLine2D([middle_line[k_start] ])) if front < end < back: k_end = get_x_value(self.x_values, end) plotpart.layers["L0"].append(PolyLine2D([middle_line[k_end]]))
def _insert_attachment_points(self, plotpart, attachment_points): for attachment_point in attachment_points: if hasattr(attachment_point, "cell"): if attachment_point.cell != self.cell: continue cell_pos = attachment_point.cell_pos elif hasattr(attachment_point, "rib"): if attachment_point.rib not in self.cell.ribs: continue if attachment_point.rib == self.cell.rib1: cell_pos = 0 align = ("left", "right") elif attachment_point.rib == self.cell.rib2: cell_pos = 1 cut_f_l = self.panel.cut_front["left"] cut_f_r = self.panel.cut_front["right"] cut_b_l = self.panel.cut_back["left"] cut_b_r = self.panel.cut_back["right"] cut_f = cut_f_l + cell_pos * (cut_f_r - cut_f_l) cut_b = cut_b_l + cell_pos * (cut_b_r - cut_b_l) if cut_f <= attachment_point.rib_pos <= cut_b: rib_pos = attachment_point.rib_pos left, right = self.get_point(rib_pos) p1 = left + cell_pos * (right - left) d = normalize(right - left) * 0.008 # 8mm if cell_pos == 1: p2 = p1 + d else: p2 = p1 - d #p1, p2 = self.get_p1_p2(attachment_point.rib_pos, which) plotpart.layers["marks"] += self.config.marks_attachment_point( p1, p2) plotpart.layers[ "L0"] += self.config.marks_laser_attachment_point(p1, p2) if self.config.insert_attachment_point_text: text_align = "left" if cell_pos > 0.7 else "right" if text_align == "right": d1 = norm(self.get_point(cut_f_l)[0] - left) d2 = norm(self.get_point(cut_b_l)[0] - left) else: d1 = norm(self.get_point(cut_f_r)[1] - right) d2 = norm(self.get_point(cut_b_r)[1] - right) bl = self.ballooned[0] br = self.ballooned[1] text_height = 0.01 * 0.8 dmin = text_height + 0.001 if d1 < dmin and d2 + d1 > 2 * dmin: offset = dmin - d1 ik = get_x_value(self.x_values, rib_pos) left = bl[bl.extend(ik, offset)] right = br[br.extend(ik, offset)] elif d2 < dmin and d1 + d2 > 2 * dmin: offset = dmin - d2 ik = get_x_value(self.x_values, rib_pos) left = bl[bl.extend(ik, -offset)] right = br[br.extend(ik, -offset)] if self.config.layout_seperate_panels and self.panel.is_lower: # rotated later p2 = left p1 = right # text_align = text_align else: p1 = left p2 = right # text_align = text_align plotpart.layers["text"] += Text( " {} ".format(attachment_point.name), p1, p2, size=0.01, # 1cm align=text_align, valign=0, height=0.8).get_vectors()
def get_p1_p2(self, x, which): side = {"left": 0, "right": 1}[which] ik = get_x_value(self.x_values, x) return self.ballooned[side][ik], self.outer_orig[side][ik]
def get_point(self, x): ik = get_x_value(self.x_values, x) return [lst[ik] for lst in self.ballooned]
def get_mesh(self, cell, numribs=0, with_numpy=False): """ Get Panel-mesh :param cell: the parent cell of the panel :param numribs: number of interpolation steps between ribs :param with_numpy: compute midribs with numpy (faster if available) :return: mesh objects consisting of triangles and quadrangles """ numribs += 1 # TODO: doesnt work for numribs=0? xvalues = cell.rib1.profile_2d.x_values ribs = [] points = [] nums = [] count = 0 for rib_no in range(numribs + 1): y = rib_no / max(numribs, 1) x1 = self.cut_front["left"] + y * (self.cut_front["right"] - self.cut_front["left"]) front = get_x_value(xvalues, x1) x2 = self.cut_back["left"] + y * (self.cut_back["right"] - self.cut_back["left"]) back = get_x_value(xvalues, x2) midrib = cell.midrib(y, with_numpy=with_numpy) ribs.append([x for x in midrib.get_positions(front, back)]) points += list(midrib[front:back]) nums.append([i + count for i, _ in enumerate(ribs[-1])]) count += len(ribs[-1]) triangles = [] # helper functions def left_triangle(l_i, r_i): return [l_i + 1, l_i, r_i] def right_triangle(l_i, r_i): return [r_i + 1, l_i, r_i] def quad(l_i, r_i): return [l_i + 1, l_i, r_i, r_i + 1] for rib_no, _ in enumerate(ribs[:-1]): num_l = nums[rib_no] num_r = nums[rib_no + 1] pos_l = ribs[rib_no] pos_r = ribs[rib_no + 1] l_i = r_i = 0 while l_i < len(num_l)-1 or r_i < len(num_r)-1: if l_i == len(num_l) - 1: triangles.append(right_triangle(num_l[l_i], num_r[r_i])) r_i += 1 elif r_i == len(num_r) - 1: triangles.append(left_triangle(num_l[l_i], num_r[r_i])) l_i += 1 elif abs(pos_l[l_i] - pos_r[r_i]) == 0: triangles.append(quad(num_l[l_i], num_r[r_i])) r_i += 1 l_i += 1 elif pos_l[l_i] <= pos_r[r_i]: triangles.append(left_triangle(num_l[l_i], num_r[r_i])) l_i += 1 elif pos_r[r_i] < pos_l[l_i]: triangles.append(right_triangle(num_l[l_i], num_r[r_i])) r_i += 1 #connection_info = {cell.rib1: np.array(ribs[0], int), # cell.rib2: np.array(ribs[-1], int)} return Mesh.from_indexed(points, {"panel_"+self.material_code: triangles}, name=self.name)