Inaccurate rendering of circular arc of angle 45 degrees.

Bug #332735 reported by Alvin Penner
2
Affects Status Importance Assigned to Milestone
Inkscape
Fix Released
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.

Revision history for this message
Alvin Penner (apenner) wrote :
Revision history for this message
Alvin Penner (apenner) wrote :

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.

Revision history for this message
Alvin Penner (apenner) wrote :

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.

Revision history for this message
Alexandre Prokoudine (alexandre-prokoudine) wrote :

I wonder if 2geom could be used here.

Revision history for this message
Alvin Penner (apenner) wrote :

    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.

Revision history for this message
Alvin Penner (apenner) wrote :

fixed in rev 20771

Changed in inkscape:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.