示例#1
0
class BallooningBezier(Ballooning):
    def __init__(self, points=None):
        if not points:
            points = [[[0, 0], [0.1, 0], [0.2, 0.14], [0.8, 0.14], [0.9, 0], [1, 0]],
                      [[0, 0], [0.1, 0], [0.2, 0.14], [0.8, 0.14], [0.9, 0], [1, 0]]]
        self.upbez = BezierCurve(points[0])
        self.lowbez = BezierCurve(points[1])
        Ballooning.__init__(self, self.upbez.interpolation(), self.lowbez.interpolation())

    def __mul__(self, other):  # TODO: Check consistency
        """Multiplication of BezierBallooning"""
        # Multiplicate as normal interpolated ballooning, then refit
        return Ballooning.__mul__(self, other)
        #self.upper = temp.upper
        #self.lower = temp.lower
        #self.upbez.fit(numpy.transpose([self.upper.x, self.upper.y]))
        #self.lowbez.fit(numpy.transpose([self.lower.x, self.lower.y]))

    def _setnumpoints(self, numpoints):
        Ballooning.__init__(self, self.upbez.interpolation(numpoints), self.lowbez.interpolation(numpoints))

    def _getnumpoints(self):
        return len(self.upper)

    Numpoints = property(_getnumpoints, _setnumpoints)
示例#2
0
class TestMarks(unittest.TestCase):
    def setUp(self):
        self.curve = BezierCurve()
        self.points = [[0., 0.], [0.5, 0.5], [1., 0.]]
        self.profile = openglider.airfoil.Profile2D()
        self.profile.compute_naca(9012, numpoints=100)

    def test_bezier_fit(self):
        nose_ind = self.profile.noseindex
        upper = BezierCurve()
        lower = BezierCurve()
        upper.fit(self.profile.data[:nose_ind+1],numpoints=10)
        lower.fit(self.profile.data[nose_ind:], numpoints=10)

        Graphics2D([
            Red,
            Line(self.profile.data),
            Green,
            Line(map(upper, numpy.linspace(0, 1, 100))),
            Line(map(lower, numpy.linspace(0, 1, 100)))
            ])

    def test_bezier_interpolation(self):
        self.curve.controlpoints = self.points
        interpolation = self.curve.interpolation(num=20)
        func = lambda x: numpy.array([x, interpolation(x)])
        Graphics2D([
            Line(map(func, numpy.linspace(0, 1, 20))),
            Green,
            Line(self.points)
            ])