2

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

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.

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?

Sources: W3C SVG, QPainterPath

Janne
  • 979
  • 4
  • 13
Christopher
  • 639
  • 1
  • 6
  • 14

1 Answers1

1

SVG elliptical arcs use "endpoint parametrization".

QPainterPath.arcTo arcs use "center parametrization".

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.


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

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

but instead of arcLength its description refers to sweepLength:

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

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

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, Δθ.

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

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • Thanks for the link, I made it past basic algebra and trigonometry but this is a little hard to understand. The bounding rect `x = w - rx`, `y = h - ry`, `w = rx * 2`, `h = ry * 2`. Hopefully figuring out `startAngle` and `arcLength` are next. – Christopher Jan 01 '12 at 03:02
  • Thanks for your help. I'm just going to ask someone how to translate those equations into python, but thank you very much for pointing me in the right direction. – Christopher Jan 02 '12 at 19:32