public static Point[] Sample(IList <Point> points, EllipseParams ellipse, int count = 20)
        {
            Contract.Requires(points != null);
            Contract.Requires(points.Count > 6);
            Contract.Requires(count > 0);
            Contract.Ensures(Contract.Result <Point[]>() != null);
            Contract.Ensures(Contract.Result <Point[]>().Length == count);

            /*using (StreamWriter writer = File.CreateText("Points.txt"))
             * {
             *  foreach (Point pnt in points)
             *  {
             *      writer.Write(pnt.X + " " + pnt.Y);
             *      writer.Write(writer.NewLine);
             *  }
             * }
             * MessageBox.Show("Done Writing Points");*/
            /*EllipseParams ellipse = new EllipseParams
             * {
             *  Center = new Point(0.9566, 0.8023),
             *  XRadius = 0.1149,
             *  YRadius = 0.0894,
             *  Degrees = -1.2418 * 180 / Math.PI
             * };*/
            var result    = new Point[count];
            var rotMatrix = new RotateTransform(ellipse.Degrees).Value;

            for (int i = 0; i < count; ++i)
            {
                var t   = 2 * Math.PI * i / (double)(count - 1);
                var vec = new Vector(ellipse.XRadius * Math.Cos(t), ellipse.YRadius * Math.Sin(t));
                result[i] = ellipse.Center + rotMatrix.Transform(vec);
            }
            return(result);
        }
        public static double ComputeDeviation(double[] conic, EllipseParams parametric, Point point)
        {
            double x = point.X;
            double y = point.Y;

            var a = conic[0];
            var b = conic[1];
            var c = conic[2];
            var d = conic[3];
            var e = conic[4];
            var f = conic[5];

            var deviation = a * x * x + b * x * y + c * y * y + d * x + e * y + f;
            var size      = Math.Min(parametric.XRadius, parametric.YRadius);

            return(Math.Abs(deviation) / size);
        }