python - 用 SVG 椭圆弧计算?

标签 python python-3.x pyqt4

我正在开发自定义 pyQt SVG 渲染器,需要帮助。这纯粹是数学问题,因此您不需要 API。

要计算 SVG 椭圆弧,您需要两个半径 rxry ;椭圆的旋转角度 x-axis-rotation ; large-arc-sweep-flag (1 或 0) 确定是否通过大于或小于 180 度绘制圆弧以及圆弧绕圆的方向; sweep-flag (1 或 0) 决定圆弧是朝负方向还是朝正方向绘制;和最后的 xy值决定圆弧的终点。

然而,QPainterPath.arcTo(self, float x, float y, float w, float h, float startAngle, float arcLenght)使用边界矩形 x, y, w, h ;起始角startAngle ; arcLength/sweepLength 是弧本身的长度。如何将 SVG 命令转换为 arcTo() 的内容方法可以用吗?

资料来源: W3C SVG , QPainterPath

最佳答案

SVG 椭圆弧使用“端点参数化”。

QPainterPath.arcTo 弧使用“中心参数化”。

您提供的 SVG 链接在标题为 "Elliptical arc implementation notes"这给出了 formulas for the conversion端点和中心参数化之间。


请注意 QPainterPath.arcTo documentation声明调用签名是

QPainterPath.arcTo (self, QRectF rect, float startAngle, float arcLength)

但不是arcLength,它的描述是指sweepLength:

Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending sweepLength degrees counter-clockwise.

奇怪的是,它说 sweepLength 是以度为单位测量的,而弧长有一个传统的数学含义,它总是一个距离。

尽管文档使用了令人困惑的参数名称“arclength”,但我认为这意味着 arcTo 的最后一个参数是扫掠角 Δθ。

因此,如果您使用 SVG 实现说明中的公式 θ1, Δθ 我认为它们可以分别用于 startAnglearcLength

关于python - 用 SVG 椭圆弧计算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8691419/

相关文章:

python3 chdir() 似乎不起作用

python - PyQt4 QAbstractListModel - 仅显示第一个数据小部件

python - 如何将字符串日期间隔转换为天数或秒数 (ISO_8601)?

python - 名称错误 : name is not defined; a variable defined if a conditon is met

python - 在Python中使用元组绘制有向图

python - PyQt GUI 操作顺序

python - 在 QVBoxLayout 中查找选中的 QRadioButton

python - 使用 += 但不 append 列表时出现 UnboundLocalError

python - 替换 python 文档字符串

python - 如何在不阻止 IP 的情况下验证电子邮件是否存在?