Example #1
0
        public static StylusPointCollection xkcd(StylusPointCollection pts)
        {
            StylusPointCollection r = resample(pts);

            if (r.Count < 2)
            {
                return(r);
            }
            StylusPoint    prev = r[0];
            CorrRandExp    r1   = new CorrRandExp(0.15, 0.99);
            CorrRandWindow r2   = new CorrRandWindow(0.1, 20);

            for (int i = 0; i < r.Count; ++i)
            {
                StylusPoint cur = r[i], next = i + 1 < r.Count?r[i + 1]:cur;
                double      dX = next.X - prev.X, dY = next.Y - prev.Y;
                double      sqrNorm = dX * dX + dY * dY;
                if (sqrNorm == 0)
                {
                    continue;
                }
                double amt    = r1.next();// +r2.next();
                double factor = amt / Math.Sqrt(sqrNorm);
                prev   = cur;
                cur.X -= factor * dY;
                cur.Y += factor * dX;
                r[i]   = cur;
            }
            return(r);
        }
Example #2
0
 public static StylusPointCollection xkcd(StylusPointCollection pts)
 {
     StylusPointCollection r = resample(pts);
     if (r.Count < 2) return r;
     StylusPoint prev = r[0];
     CorrRandExp r1 = new CorrRandExp(0.15, 0.99);
     CorrRandWindow r2 = new CorrRandWindow(0.1, 20);
     for (int i = 0; i < r.Count; ++i)
     {
         StylusPoint cur = r[i], next = i+1<r.Count?r[i + 1]:cur;
         double dX = next.X - prev.X, dY = next.Y - prev.Y;
         double sqrNorm = dX * dX + dY * dY;
         if (sqrNorm == 0)
         {
             continue;
         }
         double amt = r1.next();// +r2.next();
         double factor = amt / Math.Sqrt(sqrNorm);
         prev = cur;
         cur.X -= factor * dY;
         cur.Y += factor * dX;
         r[i] = cur;
     }
     return r;
 }