【问题标题】:Calculating with a SVG elipitical arc?用 SVG 椭圆弧计算?
【发布时间】:2012-01-01 12:37:54
【问题描述】:

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

要计算 SVG 椭圆弧,您需要两个半径 rxry;椭圆的旋转度数x-axis-rotationlarge-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

【问题讨论】:

    标签: python python-3.x pyqt4


    【解决方案1】:

    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

    创建一个占据给定矩形的弧,从 指定 startAngle 和扩展 sweepLength 度数 逆时针。

    奇怪的是,它说sweepLength 以度为单位,而弧长具有传统的数学含义,始终是距离。

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

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

    【讨论】:

    • 感谢您的链接,我已经通过了基本代数和三角学,但这有点难以理解。边界矩形x = w - rxy = h - ryw = rx * 2h = ry * 2。希望接下来是 startAnglearcLength
    • 感谢您的帮助。我只是想问别人如何将这些方程式翻译成python,但非常感谢你为我指明了正确的方向。
    猜你喜欢
    • 1970-01-01
    • 2010-12-20
    • 2015-08-06
    • 2017-12-19
    • 2020-09-16
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多