I'm trying to do SVG path calculations in Python, but I'm having problems with Arc curves.
I think the problem is the conversion from the endpoint to the parameterization of the center, but I cannot find the problem. You can find notes on how to implement it in section F6.5 of the SVG specification . I also looked at implementations in other languages, and I donβt see what they do differently.
The implementation of the My Arc object is here:
class Arc(object): def __init__(self, start, radius, rotation, arc, sweep, end): """radius is complex, rotation is in degrees, large and sweep are 1 or 0 (True/False also work)""" self.start = start self.radius = radius self.rotation = rotation self.arc = bool(arc) self.sweep = bool(sweep) self.end = end self._parameterize() def _parameterize(self):
You can verify this with the following code, which will draw curves using the Turtle module. (The raw_input () source file at the end is just that the screen does not disappear when the program exits).
arc1 = Arc(0j, 100+50j, 0, 0, 0, 100+50j) arc2 = Arc(0j, 100+50j, 0, 1, 0, 100+50j) arc3 = Arc(0j, 100+50j, 0, 0, 1, 100+50j) arc4 = Arc(0j, 100+50j, 0, 1, 1, 100+50j) import turtle t = turtle.Turtle() t.penup() t.goto(0, 0) t.dot(5, 'red') t.write('Start') t.goto(100, 50) t.dot(5, 'red') t.write('End') t.pencolor = t.color('blue') for arc in (arc1, arc2, arc3, arc4): t.penup() p = arc.point(0) t.goto(p.real, p.imag) t.pendown() for x in range(1,101): p = arc.point(x*0.01) t.goto(p.real, p.imag) raw_input()
Problem:
Each of these four elongated arcs should draw from the starting point to the ending point. However, they are made from the wrong points. Two curves go from start to start, and two go from 100, from -50 to 0.0, not from 0.0 to 100, 50.
Part of the problem is that the implementation notes give you a formula on how to make the end points of the transform shape in the center, but they donβt explain what it does geometrically, so I donβt quite understand what each step does. An explanation for this will also be useful.