bézier曲线、三角形和高阶对象的辅助对象
bezier的Python项目详细描述
Helper for Bézier Curves, Triangles, and Higher Order Objects
此库提供:
潜进去看看!
为什么是贝齐尔?
bézier曲线(和曲面等)是参数曲线 使用Bernstein basis:
将曲线定义为线性组合:
这是因为权重总和为1:
这可以通过考虑三、四等推广到更高阶。 总和为1的非负权重(在上面我们有两个 非负权重s和1 - s)。
由于bézier曲线形式简单:
- 可以轻松地将几何对象建模为参数曲线、曲面等。
- 可通过 de Casteljau’s algorithm
- 可以将凸优化技术用于许多算法(例如 曲线-曲线相交),因为曲线(和曲面等) 是基的凸组合
许多应用程序以及它们的发展历史- 描述于 “伯恩斯坦多项式基:百年retrospective”, 例如;
安装
bezierpython包可以与pip:
一起安装$ python -m pip install --upgrade bezier $ python3.7 -m pip install --upgrade bezier
bezier是开源的,因此您可以选择获取源代码 从GitHub编码并从源安装。
开始
例如,要创建曲线:
>>>nodes1=np.asfortranarray([...[0.0,0.5,1.0],...[0.0,1.0,0.0],...])>>>curve1=bezier.Curve(nodes1,degree=2)
两条曲线之间的交点可以 也要确定:
>>>nodes2=np.asfortranarray([...[0.0,0.25,0.5,0.75,1.0],...[0.0,2.0,-2.0,2.0,0.0],...])>>>curve2=bezier.Curve.from_nodes(nodes2)>>>intersections=curve1.intersect(curve2)>>>intersectionsarray([[0.31101776,0.68898224,0.,1.],[0.31101776,0.68898224,0.,1.]])>>>s_vals=np.asfortranarray(intersections[0,:])>>>points=curve1.evaluate_multi(s_vals)>>>pointsarray([[0.31101776,0.68898224,0.,1.],[0.42857143,0.42857143,0.,0.]])
然后我们可以绘制这些曲线 交叉路口:
>>>importmatplotlib.pyplotasplt>>>importseaborn>>>seaborn.set()>>>>>>ax=curve1.plot(num_pts=256)>>>_=curve2.plot(num_pts=256,ax=ax)>>>lines=ax.plot(...points[0,:],points[1,:],...marker="o",linestyle="None",color="black")>>>_=ax.axis("scaled")>>>_=ax.set_xlim(-0.125,1.125)>>>_=ax.set_ylim(-0.0625,0.625)>>>plt.show()
对于api级文档,请查看bézier python package文档。
开发
要添加功能或运行功能测试,请参见 DEVELOPMENT doc了解有关如何获取 起动。
许可证
bezier在apache 2.0许可下可用。更多 详细信息,请参见the LICENSE。