栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用SciPy的Bézier曲线拟合

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用SciPy的Bézier曲线拟合

这是一段拟合点的python代码:

'''least square qbezier fit using penrose pseudoinverse    >>> V=array    >>> E,  W,  N,  S =  V((1,0)), V((-1,0)), V((0,1)), V((0,-1))    >>> cw = 100    >>> ch = 300    >>> cpb = V((0, 0))    >>> cpe = V((cw, 0))    >>> xys=[cpb,cpb+ch*N+E*cw/8,cpe+ch*N+E*cw/8, cpe]     >>>     >>> ts = V(range(11), dtype='float')/10    >>> M = bezierM (ts)    >>> points = M*xys #produces the points on the bezier curve at t in ts    >>>     >>> control_points=lsqfit(points, M)    >>> linalg.norm(control_points-xys)<10e-5    True    >>> control_points.tolist()[1]    [12.500000000000037, 300.00000000000017]'''from numpy import array, linalg, matrixfrom scipy.misc import comb as nOkMtk = lambda n, t, k: t**(k)*(1-t)**(n-k)*nOk(n,k)bezierM = lambda ts: matrix([[Mtk(3,t,k) for k in range(4)] for t in ts])def lsqfit(points,M):    M_ = linalg.pinv(M)    return M_ * points

通常在bezier曲线上查看 动画bezier和
bezierinfo



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/639236.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号