开发者

bezier and matplotlib

Hi I'm starting from http://matplotlib.sourceforge.net/users/path_tutorial.html . I'm looking a function to get all bezier points with a fixed sampling rate.

What I'm loo开发者_JS百科king for is something like this:

interpolate(t, samplingrate)

where t is the curve parameter between 0 and 1, sampling rate is the length of the list of point returned.

in the manual page http://matplotlib.sourceforge.net/api/path_api.html?highlight=bezier and with some dir() calls I don't find anything useful

Some Help?


The Path object does not store the points along a Bezier curve, just the minimum parameters it needs. Writing your own function shouldn't be hard. How about something like this, following the expressions from wikipedia.

def quadBrezPoints(P0, P2, P1, nSamples):
    ans = numpy.zeros((nSamples,2))
    for i in xrange(nSamples):
        t = (i+0.0)/nSamples
        ans[i,0] = (1-t)**2 * P0[0] + 2*(1-t)*P1[0] + t**2 * P2[0]
        ans[i,1] = (1-t)**2 * P0[1] + 2*(1-t)*P1[1] + t**2 * P2[1]
return ans

If you want n-degree Bezier curves, just modify the function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜