# Inaccurate rendering of circular arc of angle 45 degrees.

Bug #332735 reported by Alvin Penner on 2009-02-22
Affects Status Importance Assigned to Milestone
Undecided
Unassigned

### Bug Description

Attached is an svg drawing showing a comparison of two full circles to a superimposed 90 degree arc and a superimposed 45 degree arc, such that in both cases the circle and the arc should agree exactly.
- zoom in to about 500% to confirm that the 90 degree arc superimposed on the full circle is indistinguishable from it.
- by comparison the 45 degree arc is significantly different from the full circle.
- this does not make sense because the 45 degree arc should be easier to render properly.

I cannot prove it, but I suspect that the problem may be in the formula used to calculate the curve in the file \trunk\src\sp-ellipse.cpp. This formula calculates the length of a Bezier control arm using:

line 184 : C1 = 0.552
line 223 : len = C1*(e-s)/M_PI_2

I think the formula should read : len = 4*tan((e-s)/4)/3

This formula was obtained by fitting a Bezier curve to a circular arc of angle (e-s), and forcing the slopes to be correct at the endpoints and forcing the midpoint of the Bezier curve to touch the circular arc tangentially. The formula agrees with the original equation if (e-s) is 90 degrees, but they differ significantly at smaller angles such as 45 degrees. The new formula has been tested in the file cubicsuperpath.py, and appears to work well there, as far as I can tell (svn rev 20706).

I wonder if someone could test this, to see if it helps.

 Alvin Penner (apenner) wrote on 2009-02-22: #1
 Alvin Penner (apenner) wrote on 2009-02-22: #2

patch attached.

as a side note, exactly the same code also appears in the files : draw-context.cpp, dyna-draw-context.cpp, dropper-context.cpp, tweak-context.cpp. However, in these files, it is not clear to me what the code is trying to do, so I don't know if these comments apply there.

 Alvin Penner (apenner) wrote on 2009-02-22: #3

patch attached.

as a side note, exactly the same code also appears in the files : draw-context.cpp, dyna-draw-context.cpp, dropper-context.cpp, tweak-context.cpp. However, in these files, it is not clear to me what the code is trying to do, so I don't know if these comments apply there.

 Alexandre Prokoudine (alexandre-prokoudine) wrote on 2009-02-22: #7

I wonder if 2geom could be used here.

 Alvin Penner (apenner) wrote on 2009-02-22: #8

after further inspection, it looks like the files : draw-context.cpp, dyna-draw-context.cpp, dropper-context.cpp, tweak-context.cpp need not be affected by this change. These 4 files appear to be drawing a full ellipse, not a partial ellipse, and they appear to be doing it in 4 equal quadrants, so there is no problem. At a 90 degree angle the value of C1 is perfectly acceptable. The correct value would be :
C1 = 4*tan(PI/8)/3 = 4*(sqrt(2)-1)/3 = .552285
which is close enough to .552. So there is no point in modifying these files.

However, it is still essential that the file sp-ellipse.cpp be patched, because it is used to calculate arbitrary arc angle values where the agreement will not be so good.
For example, at an arc angle of 45 degrees, the new formula predicts
len = 4*tan(PI/16)/3 = .265
while the original formula predicts
len = .552/2 = .276
This is 4 % too high, which is easily detectable on a visual display, and this 4% error is most likely causing the bulge outwards which is shown in the attached svg file.

 Alvin Penner (apenner) wrote on 2009-03-06: #9

fixed in rev 20771

 Changed in inkscape: status: New → Fix Released