用 SVG 椭圆弧计算? [英] Calculating with a SVG elipitical arc?

查看:62
本文介绍了用 SVG 椭圆弧计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on a custom pyQt SVG renderer and need help. This is purely mathematical so you won't need an API.

要计算 SVG 椭圆弧,您需要两个半径 rxry;椭圆的旋转度数 x-axis-rotation;large-arc-sweep-flag(1 或 0),用于确定圆弧的绘制角度是大于还是小于 180 度以及圆弧的方向;sweep-flag(1 或 0)决定弧线是沿负方向还是正方向绘制;最终的 x 和 y 值决定了弧的终点.

To calculate a SVG elliptical arc you need two radii rx and ry; the rotation of the ellipse in degrees x-axis-rotation; the large-arc-sweep-flag (1 or 0) that determines if an arc is drawn through greater than or less than 180 degrees and the direction of the arc around the circle; the sweep-flag (1 or 0) determines if the arc will be drawn in a negative or positive direction; and the final x and y values determine the end of the arc.

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

However, QPainterPath.arcTo(self, float x, float y, float w, float h, float startAngle, float arcLenght) uses a bounding rectangle x, y, w, h; a starting angle startAngle; and an arcLength/sweepLength the length of the arc itself. How do I translate the SVG command to something the arcTo() method can use?

来源:W3C SVGQPainterPath

推荐答案

SVG 椭圆弧使用端点参数化".

SVG elliptical arcs use "endpoint parametrization".

QPainterPath.arcTo 弧使用中心参数化".

QPainterPath.arcTo arcs use "center parametrization".

您提供的 SVG 链接在标题为"椭圆弧实施说明" 给出了 端点和中心参数化之间的转换公式.

The SVG link you kindly provided has a link near the end of the section entitled "Elliptical arc implementation notes" which gives formulas for the conversion between endpoint and center parametrization.

请注意 QPainterPath.arcTo 文档 表示调用签名是

Note that the QPainterPath.arcTo documentation states that the call signature is

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

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

but instead of arcLength its description refers to sweepLength:

创建一个占据给定矩形的弧,从指定 startAngle 和扩展扫描长度度逆时针.

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

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

Oddly, it says that sweepLength is measured in degrees, while arclength has a conventional mathematical meaning which is always a distance.

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

Even though the documentation uses the confusing parameter name "arclength" I think it meant to say that the last argument to arcTo is the sweep angle, Δθ.

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

So if you use the formulas from the SVG implementation notes for θ1, Δθ I think they can be used for startAngle and arcLength, respectively.

这篇关于用 SVG 椭圆弧计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆