How can I draw a bezier curve using Python's PIL?

发布于 2021-01-29 15:09:21

I’m using Python’s Imaging Library and I would like to draw some bezier
curves. I guess I could calculate pixel by pixel but I’m hoping there is
something simpler.

关注者
0
被浏览
106
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    A bezier curve isn’t that hard to draw yourself. Given three points A, B,
    C you require three linear interpolations in order to draw the curve. We use
    the scalar t as the parameter for the linear interpolation:

    P0 = A * t + (1 - t) * B
    P1 = B * t + (1 - t) * C
    

    This interpolates between two edges we’ve created, edge AB and edge BC. The
    only thing we now have to do to calculate the point we have to draw is
    interpolate between P0 and P1 using the same t like so:

    Pfinal = P0 * t + (1 - t) * P1
    

    There are a couple of things that need to be done before we actually draw the
    curve. First off we have will walk some dt (delta t) and we need to be aware
    that 0 <= t <= 1. As you might be able to imagine, this will not give us a
    smooth curve, instead it yields only a discrete set of positions at which to
    plot. The easiest way to solve this is to simply draw a line between the
    current point and the previous point.



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看