如何使用 wxPython 给定四个点绘制贝塞尔曲线?
在我看来, DC 的唯一支持任何类型的曲线都带有样条线。是否有任何库添加贝塞尔功能,或者有没有办法将贝塞尔曲线转换为样条曲线?
It appears to me that the DC's only support for curves of any sort is with splines. Are there any libraries that add bezier functionality, or is there a way to convert a bezier curve into a spline?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
给定 4 个控制点,相关三次贝塞尔曲线的公式不难计算。一旦计算了曲线上的一组点,您可以使用
DC.DrawLines
来绘制它。有一个用于计算广义贝塞尔曲线上的点的Python实现(无耻插件)这里。它是通用的,因为它可以接受任意数量的控制点 (>2) 作为 make_bezier 的输入。如果您只想要 4 个控制点版本,您可以完全删除
pascal_row
并替换为
Given 4 control points, the formula for the associated cubic Bezier curve is not hard to compute. Once you calculate a set of points on the curve, you could use
DC.DrawLines
to draw it.There is a python implementation for calculating points on generalized Bezier curves (shameless plug) here. It's generalized in the sense that it can accept an arbitrary number of control points (>2) as input to
make_bezier
. If you want only the 4-control point version, you can cut outpascal_row
entirely and replacewith
经过一番谷歌搜索后,我想我会选择 wx.GraphicsContext< /a>,支持 wx.GraphicsPath。除了抗锯齿之外,它似乎完全满足了我的需要(根据此页面)
After a little googling, I think I'll go with wx.GraphicsContext, which supports wx.GraphicsPath. It appears to have exactly what I need, in addition to anti-aliasing (according to this page)