Пример #1
0
        private void DrawBezier4(Graphics g, CPoint p0, CPoint p1, CPoint p2, CPoint p3)
        {
            var prev = p0;

            for (int i = 1; i < NUMBER_OF_STEPS; ++i)
            {
                var t  = (float)i / (NUMBER_OF_STEPS - 1);
                var q0 = p0 * (1 - t) + p1 * t;
                var q1 = p1 * (1 - t) + p2 * t;
                var q2 = p2 * (1 - t) + p3 * t;
                var r0 = q0 * (1 - t) + q1 * t;
                var r1 = q1 * (1 - t) + q2 * t;
                var b  = r0 * (1 - t) + r1 * t;
                g.DrawLine(boldPen, prev, b);
                prev = b;
            }
        }
Пример #2
0
            private int FindNearestPoint(CPoint c)
            {
                var minDistance = float.MaxValue;
                var minIndex    = -1;

                for (int i = 0; i < plotter.points.Count; ++i)
                {
                    var p        = plotter.points[i];
                    var distance = Math.Abs(p.X - c.X) + Math.Abs(p.Y - c.Y);
                    if (minDistance < distance)
                    {
                        continue;
                    }
                    minDistance = distance;
                    minIndex    = i;
                }
                return(minIndex);
            }