Пример #1
0
        private LineSegment lineSegmentPerpendicularTo(LineSegment seg, float relativeLengthFraction) 
        {
          float x0 = seg.P1.X,
                y0 = seg.P1.Y,
                x1 = seg.P2.X,
                y1 = seg.P2.Y;

          float dx = x1 - x0,
                dy = y1 - y0;

          float xa = x1 + relativeLengthFraction / 2 * dy,
               ya = y1 - relativeLengthFraction / 2 * dx,
               xb = x1 - relativeLengthFraction / 2 * dy,
               yb = y1 + relativeLengthFraction / 2 * dx;

          return new LineSegment()
          {
              P1 = new PointF(xa, ya),
              P2 = new PointF(xb, yb)
          };
        }
Пример #2
0
        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!_isMouseDown) return;

            Graphics g = panel1.CreateGraphics();
            g.SmoothingMode = SmoothingMode.HighQuality;
            
            _counter += 1;
            _points[_counter] = e.Location;
            
            LineSegment[] ls = new LineSegment[4];
            

            if (_counter == 4) {
                
                GraphicsPath path = new GraphicsPath();

                _points[3] = new Point((_points[2].X + _points[4].X) / 2,
                                       (_points[2].Y + _points[4].Y) / 2);

                if (_isFirstTouchPoint) {
                    ls[0] = new LineSegment(){
                        P1 = _points[0],
                        P2 = _points[0]
                    };
                    _isFirstTouchPoint = false;
                } 
                else {
                    ls[0] = _lastSegmentOfPrev;
                }
                
                float frac1 = FF / clamp(len_sq(_points[0], _points[1]), LOWER, UPPER);
                float frac2 = FF / clamp(len_sq(_points[1], _points[2]), LOWER, UPPER);
                float frac3 = FF / clamp(len_sq(_points[2], _points[3]), LOWER, UPPER);

                ls[1] = lineSegmentPerpendicularTo(new LineSegment()
                {
                    P1 = _points[0],
                    P2 = _points[1]
                }, frac1);

                ls[2] = lineSegmentPerpendicularTo(new LineSegment()
                {
                    P1 = _points[1],
                    P2 = _points[2]
                }, frac2);

                ls[3] = lineSegmentPerpendicularTo(new LineSegment()
                {
                    P1 = _points[2],
                    P2 = _points[3]
                }, frac3);

                path.AddBezier(ls[0].P1, ls[1].P1, ls[2].P1, ls[3].P1);
                path.AddLine(ls[3].P1, ls[3].P2);
                path.AddBezier(ls[3].P2, ls[2].P2, ls[1].P2, ls[0].P2);
                path.CloseFigure();

                g.DrawPath(Pens.Black, path);
                g.FillPath(Brushes.Black, path);

                _lastSegmentOfPrev = ls[3];

                _points[0] = _points[3];
                _points[1] = _points[4];
                _counter = 1;
            }
        }
Пример #3
0
        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!_isMouseDown)
            {
                return;
            }

            Graphics g = panel1.CreateGraphics();

            g.SmoothingMode = SmoothingMode.HighQuality;

            _counter         += 1;
            _points[_counter] = e.Location;

            LineSegment[] ls = new LineSegment[4];


            if (_counter == 4)
            {
                GraphicsPath path = new GraphicsPath();

                _points[3] = new Point((_points[2].X + _points[4].X) / 2,
                                       (_points[2].Y + _points[4].Y) / 2);

                if (_isFirstTouchPoint)
                {
                    ls[0] = new LineSegment()
                    {
                        P1 = _points[0],
                        P2 = _points[0]
                    };
                    _isFirstTouchPoint = false;
                }
                else
                {
                    ls[0] = _lastSegmentOfPrev;
                }

                float frac1 = FF / clamp(len_sq(_points[0], _points[1]), LOWER, UPPER);
                float frac2 = FF / clamp(len_sq(_points[1], _points[2]), LOWER, UPPER);
                float frac3 = FF / clamp(len_sq(_points[2], _points[3]), LOWER, UPPER);

                ls[1] = lineSegmentPerpendicularTo(new LineSegment()
                {
                    P1 = _points[0],
                    P2 = _points[1]
                }, frac1);

                ls[2] = lineSegmentPerpendicularTo(new LineSegment()
                {
                    P1 = _points[1],
                    P2 = _points[2]
                }, frac2);

                ls[3] = lineSegmentPerpendicularTo(new LineSegment()
                {
                    P1 = _points[2],
                    P2 = _points[3]
                }, frac3);

                path.AddBezier(ls[0].P1, ls[1].P1, ls[2].P1, ls[3].P1);
                path.AddLine(ls[3].P1, ls[3].P2);
                path.AddBezier(ls[3].P2, ls[2].P2, ls[1].P2, ls[0].P2);
                path.CloseFigure();

                g.DrawPath(Pens.Black, path);
                g.FillPath(Brushes.Black, path);

                _lastSegmentOfPrev = ls[3];

                _points[0] = _points[3];
                _points[1] = _points[4];
                _counter   = 1;
            }
        }