Esempio n. 1
0
 def __call__(self, p1, p2):
     if self.rotation:
         center = (p1+p2)/2
         rot = rotation_2d(self.rotation)
         return [PolyLine2D([center + rot.dot(p1-center), center+rot.dot(p2-center)], name=self.name)]
     else:
         return [PolyLine2D([p1, p2], name=self.name)]
Esempio n. 2
0
 def shape_flattened(self):
     """
     Projected Shape of the glider (as it would lie on the ground - flattened)
     """
     rot = rotation_2d(np.pi / 2)
     front, back = flatten_list(self.get_spanwise(0), self.get_spanwise(1))
     return Shape([rot.dot(p) for p in front], [rot.dot(p) for p in back])
Esempio n. 3
0
    def get_sequence(self, num=20):
        lst = []
        end = vector_angle(self.r, numpy.array(self.p3) - self.center)
        for angle in numpy.linspace(0, end, num):
            lst.append(self.center + rotation_2d(angle).dot(self.r))

        return PolyLine2D(lst)
Esempio n. 4
0
    def apply(self, inner_lists, outer_left, outer_right, amount_3d=None):
        #p1 = inner_lists[0][0][inner_lists[0][1]]  # [[list1,pos1],[list2,pos2],...]
        #p2 = inner_lists[-1][0][inner_lists[-1][1]]
        p1, p2 = self.get_p1_p2(inner_lists, amount_3d)
        indices = self._get_indices(inner_lists, amount_3d)
        normvector = normalize(rotation_2d(math.pi / 2).dot(p1 - p2))

        newlist = []
        # todo: sort by distance
        cuts_left = list(
            outer_left.cut(p1, p2, inner_lists[0][1], extrapolate=True))
        cuts_left.sort(key=lambda cut: abs(cut[1]))
        leftcut_index = cuts_left[0][0]
        leftcut = outer_left[leftcut_index]

        newlist.append(leftcut)
        newlist.append(leftcut + normvector * self.amount)

        for thislist in inner_lists:
            newlist.append(thislist[0][thislist[1]] + normvector * self.amount)

        cuts_right = list(
            outer_right.cut(p1, p2, inner_lists[-1][1], extrapolate=True))
        cuts_right.sort(key=lambda cut: abs(cut[1]))
        rightcut_index = cuts_right[0][0]
        rightcut = outer_right[rightcut_index]

        newlist.append(rightcut + normvector * self.amount)
        newlist.append(rightcut)

        curve = PolyLine2D(newlist)

        return CutResult(curve, leftcut_index, rightcut_index, indices)
Esempio n. 5
0
    def apply(self, inner_lists, outer_left, outer_right, amount_3d=None):
        p1, p2 = self.get_p1_p2(inner_lists, amount_3d)
        indices = self._get_indices(inner_lists, amount_3d)

        normvector = normalize(rotation_2d(math.pi / 2).dot(p1 - p2))

        leftcut_index = next(
            outer_left.cut(p1, p2, inner_lists[0][1], extrapolate=True))
        rightcut_index = next(
            outer_right.cut(p1, p2, inner_lists[-1][1], extrapolate=True))

        index_left = leftcut_index[0]
        index_right = rightcut_index[0]

        leftcut = outer_left[index_left]
        rightcut = outer_right[index_right]

        leftcut_index_2 = outer_left.cut(p1 - normvector * self.amount,
                                         p2 - normvector * self.amount,
                                         inner_lists[0][1],
                                         extrapolate=True)
        rightcut_index_2 = outer_right.cut(p1 - normvector * self.amount,
                                           p2 - normvector * self.amount,
                                           inner_lists[-1][1],
                                           extrapolate=True)

        leftcut_2 = outer_left[next(leftcut_index_2)[0]]
        rightcut_2 = outer_right[next(rightcut_index_2)[0]]
        diff_l, diff_r = leftcut - leftcut_2, rightcut - rightcut_2

        curve = PolyLine2D(
            [leftcut, leftcut + diff_l, rightcut + diff_r, rightcut])

        return CutResult(curve, leftcut_index[0], rightcut_index[0], indices)
Esempio n. 6
0
    def _insert_text(self, text):
        inner, outer = self._get_inner_outer(self.config.rib_text_pos)
        diff = outer - inner

        p1 = inner + diff / 2
        p2 = p1 + rotation_2d(np.pi / 2).dot(diff)

        _text = Text(text, p1, p2, size=norm(outer - inner) * 0.5, valign=0)
        #_text = Text(text, p1, p2, size=0.05)
        self.plotpart.layers["text"] += _text.get_vectors()
Esempio n. 7
0
    def rotate(self, angle, startpoint=None, radians=True):
        """
        Rotate counter-clockwise around a (non)given startpoint [rad]
        """
        if not radians:
            angle = np.pi * angle / 180
        rotation_matrix = rotation_2d(angle)
        new_data = []
        for point in self.data:
            if startpoint is not None:
                new_data.append(startpoint +
                                rotation_matrix.dot(point - startpoint))
            else:
                new_data.append(rotation_matrix.dot(point))
        self.data = new_data

        return self
Esempio n. 8
0
    def apply(self, inner_lists, outer_left, outer_right, amount_3d=None):
        p1, p2 = self.get_p1_p2(inner_lists, amount_3d)
        indices = self._get_indices(inner_lists, amount_3d)

        normvector = normalize(rotation_2d(math.pi / 2).dot(p1 - p2))

        left_start_index = next(
            outer_left.cut(p1, p2, inner_lists[0][1], extrapolate=True))[0]
        right_start_index = next(
            outer_right.cut(p1, p2, inner_lists[-1][1], extrapolate=True))[0]

        pp1 = p1 - normvector * self.amount
        pp2 = p2 - normvector * self.amount
        left_end_index = next(
            outer_left.cut(pp1, pp2, inner_lists[0][1], extrapolate=True))[0]
        right_end_index = next(
            outer_right.cut(pp1, pp2, inner_lists[-1][1], extrapolate=True))[0]

        left_start = outer_left[left_start_index]
        left_end = outer_left[left_end_index]
        right_start = outer_right[right_start_index]
        right_end = outer_right[right_end_index]

        left_piece = outer_left[left_end_index:left_start_index]
        right_piece = outer_right[right_end_index:right_start_index]
        left_piece_mirrored = left_piece[::-1]
        right_piece_mirrored = right_piece[::-1]
        left_piece_mirrored.mirror(p1, p2)
        right_piece_mirrored.mirror(p1, p2)

        # mirror to (p1-p2) -> p'=p-2*(p.normvector)
        last_left, last_right = left_start, right_start
        new_left, new_right = PolyLine2D(None), PolyLine2D(None)

        for i in range(self.num_folds):
            left_this = left_piece if i % 2 else left_piece_mirrored
            right_this = right_piece if i % 2 else right_piece_mirrored
            left_this.move(last_left - left_this[0])
            right_this.move(last_right - right_this[0])
            new_left += left_this
            new_right += right_this
            last_left, last_right = new_left.data[-1], new_right.data[-1]

        curve = new_left + new_right[::-1]

        return CutResult(curve, left_start_index, right_start_index, indices)
Esempio n. 9
0
    def apply(self, inner_lists, outer_left, outer_right, amount_3d=None):
        """

        :param inner_lists:
        :param outer_left:
        :param outer_right:
        :param amount_3d: list of 3d-shaping amounts
        :return:
        """

        inner_new = []
        point_list = []

        for offset, lst in zip(amount_3d, inner_lists):
            curve, ik = lst
            ik_new = curve.extend(ik, offset)
            inner_new.append([curve, ik_new])

        p1, p2 = self.get_p1_p2(inner_lists, amount_3d)
        normvector = normalize(rotation_2d(math.pi / 2).dot(p1 - p2))

        leftcut_index = next(
            outer_left.cut(p1, p2, inner_lists[0][1], extrapolate=True))
        rightcut_index = next(
            outer_right.cut(p1, p2, inner_lists[-1][1], extrapolate=True))

        index_left = leftcut_index[0]
        index_right = rightcut_index[0]

        leftcut = outer_left[index_left]
        rightcut = outer_right[index_right]

        point_list.append(leftcut)
        point_list.append(leftcut + normvector * self.amount)

        for curve, ik in inner_new:
            point_list.append(curve[ik] + normvector * self.amount)

        point_list.append(rightcut + normvector * self.amount)
        point_list.append(rightcut)

        curve = PolyLine2D(point_list)

        return CutResult(curve, index_left, index_right,
                         [x[1] for x in inner_new])
Esempio n. 10
0
 def __init__(self, func, rotation, center=True):
     self.angle = rotation
     self.rotation = rotation_2d(rotation)
     super(Rotate, self).__init__(func)