Hi,
I have noticed a few parts in lib2geom that give unstable output. I am trying to figure out what causes this and possible how to fix it:
In lib2geom’s toy example curvature-test.cpp, we fit osculating circle at a point of a given curve. We can slide along time parameter to fit osculating circle at different point on the curve. I modify the code a little to output the curvature plot of the curve in two ways:
1) Using D2<SBasis> to build curvature graph. Each segment in D2<SBasis> is a copy of SBasis from curvature curve K, offset by a constant. (as seen in RED). Piecewise<SBasis> K = curvature(B); 2) Draw the graph directly by cairo_move_to(), cairo_line_to(). (as seen in GREEN).
The normal result would look like this:
However, when I hover my mouse around randomly (no input has been changed), the curve being fitted using D2<SBasis> will go wild randomly too:
Notice that the green curve that plots curvature with cairo methods is stable. Does anyone know if we have a fix for this? Here is the source file:
The part that seems to give problems is when we define D2<> segment with linear interpolation:
for(unsigned ix = 0; ix < K.segs.size(); ix++) { D2<SBasis> Kxy; Kxy[1] = Linear(450) - K.segs[ix]*400; Kxy[0] = Linear(300*K.cuts[ix] + 150, 300*K.cuts[ix+1] + 150); cairo_d2_sb(cr, Kxy); cairo_set_source_rgba (cr, 1., 0., 0., 0.8); cairo_stroke(cr); }
I did something similar to this in other toy example and got the same instability. I believe that the instability comes from using K.segs[] to define new SBasis (K is a Piecewise<SBasis> that contains curvature of the curve). If I create D2<SBasis> by purely linear segments, my output is very stable:
dd = 0.1; for (double tt = 0; tt < 1.0; tt += dd) { D2<SBasis> Kxy; Kxy[1] = SBasis(450 - K(tt)*400, 450 - K(tt+dd)*400); Kxy[0] = SBasis(150 + 300*(tt), 150 + 300*(tt+dd)); cairo_d2_sb(cr, Kxy); cairo_set_source_rgba (cr, 1., 0., 0., 0.8); cairo_stroke(cr); }
Would appreciate some helps to fix the issue here.
Regards, _______________________ Papoj "Hua" Thamjaroenporn pt2277@...3110...