public static void Draw(Canvas canvas, List<LinePoint> points, Brush stroke, bool clear = true)
        {
            if (clear)
            {
                canvas.Children.Clear();
            }

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();
            PathGeometry myPathGeometry = new PathGeometry();

            foreach (LinePoint p in points)
            {
                PathFigure myPathFigure = new PathFigure();
                myPathFigure.StartPoint = p.StartPoint;

                LineSegment myLineSegment = new LineSegment();
                myLineSegment.Point = p.EndPoint;

                PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                myPathSegmentCollection.Add(myLineSegment);

                myPathFigure.Segments = myPathSegmentCollection;

                myPathFigureCollection.Add(myPathFigure);
            }

            myPathGeometry.Figures = myPathFigureCollection;
            Path myPath = new Path();
            myPath.Stroke = stroke == null ? Brushes.Black : stroke;
            myPath.StrokeThickness = 1;
            myPath.Data = myPathGeometry;

            canvas.Children.Add(myPath);
        }
		private void AddCircularArcGraph(Point startPoint, Point endPoint, Size size)
		{
			PathFigure pf = new PathFigure();
			pf.StartPoint = new Point(startPoint.X, startPoint.Y);

			ArcSegment arcSegment = new ArcSegment();
			arcSegment.Point = new Point(endPoint.X, endPoint.Y);
			arcSegment.Size = size;
			arcSegment.SweepDirection = SweepDirection.Counterclockwise;

			PathSegmentCollection psc = new PathSegmentCollection();
			psc.Add(arcSegment);

			pf.Segments = psc;

			PathFigureCollection pfc = new PathFigureCollection();
			pfc.Add(pf);

			PathGeometry pg = new PathGeometry();
			pg.Figures = pfc;

			var path = new Path();
			path.Stroke = Brushes.Black;
			path.StrokeThickness = 1;
			path.Data = pg;
			path.Fill = Brushes.Orange;
			path.Stretch = Stretch.Fill;

			var viewportPanel = new ViewportHostPanel();
			ViewportPanel.SetViewportBounds(path, new DataRect(0, 0, 50, 50));
			viewportPanel.Children.Add(path);
			plotter.Children.Add(viewportPanel);
		}
            private Geometry GetDefaultGlyph()
            {
                var x1 = _columnHeader.ActualWidth - 13;
                var x2 = x1 + 10;
                var x3 = x1 + 5;
                var y1 = _columnHeader.ActualHeight / 2 - 3;
                var y2 = y1 + 5;

                if (_direction == ListSortDirection.Ascending)
                {
                    var tmp = y1;
                    y1 = y2;
                    y2 = tmp;
                }

                var pathSegmentCollection = new PathSegmentCollection();

                pathSegmentCollection.Add(new LineSegment(new Point(x2, y1), true));
                pathSegmentCollection.Add(new LineSegment(new Point(x3, y2), true));

                var pathFigure = new PathFigure(new Point(x1, y1), pathSegmentCollection, true);

                var pathFigureCollection = new PathFigureCollection();

                pathFigureCollection.Add(pathFigure);

                var pathGeometry = new PathGeometry(pathFigureCollection);

                return(pathGeometry);
            }
Exemple #4
0
        public PathFigure AddArc(int start, int end)
        {
            int horizontalPostion = 100;

            var startPoint = new Point(horizontalPostion, start);
            var endPoint = new Point(horizontalPostion, end);

            PathFigure pathFigure = new PathFigure();
            pathFigure.StartPoint = startPoint;

            ArcSegment arcSeg = new ArcSegment();
            arcSeg.Point = endPoint;
            arcSeg.Size = new Size(25, 25);
            arcSeg.IsLargeArc = true;
            arcSeg.SweepDirection = SweepDirection.Clockwise;
            arcSeg.RotationAngle = 90;

            var arrowhead = new Polygon();
            arrowhead.Stroke = Brushes.Black;
            arrowhead.StrokeThickness = 2;
            arrowhead.Points.Add(new Point(endPoint.X - 4, endPoint.Y));
            arrowhead.Points.Add(new Point(endPoint.X + 4, endPoint.Y + 3));
            arrowhead.Points.Add(new Point(endPoint.X + 4, endPoint.Y - 3));
            arrowhead.Fill = Brushes.Black;

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
            myPathSegmentCollection.Add(arcSeg);
            pathFigure.Segments = myPathSegmentCollection;

            _pathFigureCollection.Add(pathFigure);

            _root.Children.Add(arrowhead);

            return pathFigure;
        }
Exemple #5
0
        public override Path getPath()
        {
            if (path.Data == null)
            {
                PathFigure myPathFigure = new PathFigure();
                myPathFigure.StartPoint = new Point(start.x, start.y);

                LineSegment myLineSegment = new LineSegment();
                myLineSegment.Point = new Point(finish.x, finish.y);

                PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                myPathSegmentCollection.Add(myLineSegment);

                myPathFigure.Segments = myPathSegmentCollection;

                PathFigureCollection myPathFigureCollection = new PathFigureCollection();
                myPathFigureCollection.Add(myPathFigure);

                PathGeometry myPathGeometry = new PathGeometry();
                myPathGeometry.Figures = myPathFigureCollection;

                path.Stroke          = Brushes.Black;
                path.StrokeThickness = 1;
                path.Data            = myPathGeometry;
            }
            return(path);
        }
Exemple #6
0
        public static void DrawPolygon(this DrawingContext drawingContext, Point[] points, double width, Color color, bool fill)
        {
            if (points.Length > 0)
            {
                var figure = new PathFigure {
                    StartPoint = points[0]
                };

                var myPathSegmentCollection = new PathSegmentCollection();
                for (var i = 1; i < points.Length; i++)
                {
                    myPathSegmentCollection.Add(new LineSegment(points[i], true));
                }

                figure.Segments = myPathSegmentCollection;
                var pathGeometry = new PathGeometry();
                pathGeometry.Figures.Add(figure);

                var brush = new SolidColorBrush(color);
                var pen   = new Pen(brush, width);
                if (fill)
                {
                    drawingContext.DrawGeometry(brush, null, pathGeometry);
                }
                else
                {
                    drawingContext.DrawGeometry(null, pen, pathGeometry);
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Creates figure by joining the given points.
        /// </summary>
        protected PathGeometry CreatePathFigure(IEnumerable <Point2Dmm[]> geometryPointClusters)
        {
            var figures = new List <PathFigure>();

            foreach (var geometryPoints in geometryPointClusters)
            {
                var pathSegments = new PathSegmentCollection();
                var firstPoint   = new Point(0, 0);
                var isFirst      = true;
                foreach (var point in geometryPoints)
                {
                    var visualPoint = ConvertToVisual(point);

                    pathSegments.Add(new LineSegment(visualPoint, !isFirst));
                    if (isFirst)
                    {
                        firstPoint = visualPoint;
                    }
                    isFirst = false;
                }
                var figure = new PathFigure(firstPoint, pathSegments, false);
                figures.Add(figure);
            }
            var geometry = new PathGeometry(figures, FillRule.EvenOdd, Transform.Identity);

            return(geometry);
        }
        /// <summary>
        /// Returns the Glyph to display
        /// </summary>
        /// <returns>Glyph object</returns>
        private Geometry GetDefaultGlyph()
        {
            double x1 = this.columnHeader.ActualWidth - 13;
            double x2 = x1 + 10;
            double x3 = x1 + 5;
            double y1 = (this.columnHeader.ActualHeight / 2) - 3;
            double y2 = y1 + 5;

            if (this.direction == ListSortDirection.Ascending)
            {
                double tmp = y1;
                y1 = y2;
                y2 = tmp;
            }

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
            pathSegmentCollection.Add(new LineSegment(new Point(x2, y1), true));
            pathSegmentCollection.Add(new LineSegment(new Point(x3, y2), true));

            PathFigure pathFigure = new PathFigure(new Point(x1, y1), pathSegmentCollection, true);

            PathFigureCollection pathFigureCollection = new PathFigureCollection();
            pathFigureCollection.Add(pathFigure);

            PathGeometry pathGeometry = new PathGeometry(pathFigureCollection);
            return pathGeometry;
        }
        /*  将相邻两点连线
        protected override void OnRender(DrawingContext dc)
        {
            if (InternalChildren.Count < 2)
            {
                base.OnRender(dc);
                return;
            }

            Point? StartPoint = null;
            Point? EndPoint = null;

            for (int index = 0; index < InternalChildren.Count; index++)
            {
                UIElement CurChhild = this.Children[index];
                Vector CurV = VisualTreeHelper.GetOffset(CurChhild);

                if (index == 0)
                    StartPoint = new Point(CurV.X + CurChhild.RenderSize.Width / 2, CurV.Y + CurChhild.RenderSize.Height / 2);
                else
                    EndPoint = new Point(CurV.X + CurChhild.RenderSize.Width / 2, CurV.Y + CurChhild.RenderSize.Height / 2);

                if (StartPoint != null && EndPoint != null)
                {
                    dc.DrawLine(new Pen(LineBrush, 1.0), StartPoint.Value, EndPoint.Value);
                    StartPoint = EndPoint;
                }
            } 
        }
        */

        // 由LineSegment连接相邻两点并最终构成Path
        protected override void OnRender(DrawingContext dc)
        {
            if (InternalChildren.Count < 2)
            {
                base.OnRender(dc);
                return;
            }

            PathSegmentCollection segmentCollection = new PathSegmentCollection();
            PathFigure pathFigure = new PathFigure() { Segments = segmentCollection }; 

            for (int index = 0; index < InternalChildren.Count; index++)
            {
                UIElement CurChhild = this.Children[index];
                Vector CurV = VisualTreeHelper.GetOffset(CurChhild);

                if (index == 0)
                    pathFigure.StartPoint = new Point(CurV.X + CurChhild.RenderSize.Width / 2, CurV.Y + CurChhild.RenderSize.Height / 2);
                else
                    segmentCollection.Add(new LineSegment() { Point = new Point(CurV.X + CurChhild.RenderSize.Width / 2, CurV.Y + CurChhild.RenderSize.Height / 2) });
            }
 
            PathGeometry pathGeometry = new PathGeometry() { Figures = new PathFigureCollection() { pathFigure } };
            dc.DrawGeometry(Brushes.Transparent, new Pen(LineBrush, 1.0), pathGeometry);
        }
        private PathSegmentCollection CreateTopLeftSegments(Rect rect1, Rect rect2, Vector dist, Orientation orientation)
        {
            PathSegmentCollection pathSegments = new PathSegmentCollection();

            LineSegment ls1 = new LineSegment();
            LineSegment ls2 = new LineSegment();
            LineSegment ls3 = new LineSegment();

            switch (orientation)
            {
            case Orientation.Horizontal:
                ls1.Point = new Point(rect1.Right + dist.X / 8, rect1.Top + rect1.Height / 2);
                ls2.Point = new Point(rect2.Left - dist.X / 8, rect2.Top + rect2.Height / 2);
                ls3.Point = new Point(rect2.Left, rect2.Top + rect2.Height / 2);
                break;

            case Orientation.Vertical:
                ls1.Point = new Point(rect1.Left + rect1.Width / 2, rect1.Bottom + dist.Y / 8);
                ls2.Point = new Point(rect2.Left + rect2.Width / 2, rect2.Top - dist.Y / 8);
                ls3.Point = new Point(rect2.Left + rect2.Width / 2, rect2.Top);
                break;
            }

            pathSegments.Add(ls1);
            pathSegments.Add(ls2);
            pathSegments.Add(ls3);

            return(pathSegments);
        }
        public void Draw(EasingFunctionBase easingFunction)
        {
            canvas1.Children.Clear();


            PathSegmentCollection pathSegments = new PathSegmentCollection();

            for (double i = 0; i < 1; i += _samplingInterval)
            {
                double x = i * canvas1.Width;
                double y = easingFunction.Ease(i) * canvas1.Height;

                var segment = new LineSegment();
                segment.Point = new Point(x, y);

                pathSegments.Add(segment);

            }
            var p = new Path();
            p.Stroke = new SolidColorBrush(Colors.Black);
            p.StrokeThickness = 3;
            PathFigureCollection figures = new PathFigureCollection();
            figures.Add(new PathFigure() { Segments = pathSegments });
            p.Data = new PathGeometry() { Figures = figures };
            canvas1.Children.Add(p);
        }
        private void RenderPolygon(DrawingContext drawingContext)
        {
            var fillBrush = Brushes.LawnGreen;
            var borderPen = new Pen(Brushes.Black,1.0);

            PathFigure myPathFigure = new PathFigure();
            myPathFigure.StartPoint = maxPoints[0];

            //PolyLineSegment seg = new PolyLineSegment(

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            for (int i = 1; i < maxPoints.Count; i++)
            {
                myPathSegmentCollection.Add(new LineSegment(maxPoints[i], true));
            }
            for (int i = minPoints.Count - 1; i >= 0; i--)
            {
                myPathSegmentCollection.Add(new LineSegment(minPoints[i], true));
            }

            myPathFigure.Segments = myPathSegmentCollection;
            PathGeometry myPathGeometry = new PathGeometry();
            
            myPathGeometry.Figures.Add(myPathFigure);

            drawingContext.DrawGeometry(fillBrush, borderPen, myPathGeometry);
        }
Exemple #13
0
        public PathGeometry Plotter()
        {
            PathFigure            pathFigure            = new PathFigure();
            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            if (points.Count > 0)
            {
                pathFigure.StartPoint = points[0];
                for (int i = 0; i < points.Count; i++)
                {
                    LineSegment lineSegment = new LineSegment
                    {
                        Point = points[i]
                    };
                    pathSegmentCollection.Add(lineSegment);
                }
            }
            pathFigure.Segments = pathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection
            {
                pathFigure
            };

            PathGeometry myPathGeometry = new PathGeometry
            {
                Figures = myPathFigureCollection
            };

            return(myPathGeometry);
        }
Exemple #14
0
        private static Path getPathFromSegment(Point startPoint, PathSegment seg)
        {
            PathFigure myPathFigure2 = new PathFigure();

            myPathFigure2.StartPoint = new Point(startPoint.X, startPoint.Y);

            PathSegmentCollection myPathSegmentCollection2 = new PathSegmentCollection();

            myPathSegmentCollection2.Add(seg);

            myPathFigure2.Segments = myPathSegmentCollection2;

            PathFigureCollection myPathFigureCollection2 = new PathFigureCollection();

            myPathFigureCollection2.Add(myPathFigure2);


            PathGeometry myPathGeometry2 = new PathGeometry();

            myPathGeometry2.Figures = myPathFigureCollection2;

            Path myPath2 = new Path();

            myPath2.Data = myPathGeometry2;
            return(myPath2);
        }
Exemple #15
0
        /// <summary>
        /// Given a list of points, return a WPF PathGeometry.  This is a helper method
        /// that can be used to create a simple Geometry composed of straight lines.
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        public static PathGeometry GeometryFromPoints(Point[] points)
        {
            PolyLineSegment pls = new PolyLineSegment();

            foreach (Point p in points)
            {
                pls.Points.Add(p);
            }

            PathSegmentCollection segs = new PathSegmentCollection();

            segs.Add(pls);
            PathFigure fig = new PathFigure()
            {
                Segments = segs, StartPoint = points[points.Length - 1]
            };

            PathFigureCollection figs = new PathFigureCollection();

            figs.Add(fig);

            return(new PathGeometry()
            {
                Figures = figs
            });
        }
Exemple #16
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            if (path.Data == null)
            {
                var myPathFigure = new PathFigure();

                myPathFigure.StartPoint = new Point(10, 50);;
                var myLineSegment = new LineSegment();
                CurrentPosition     = new Point(200, 70);
                myLineSegment.Point = CurrentPosition;

                var myPathSegmentCollection = new PathSegmentCollection();
                myPathSegmentCollection.Add(myLineSegment);

                myPathFigure.Segments = myPathSegmentCollection;
                MyPathFigure          = myPathFigure;

                var myPathFigureCollection = new PathFigureCollection();
                myPathFigureCollection.Add(myPathFigure);

                var myPathGeometry = new PathGeometry();
                myPathGeometry.Figures = myPathFigureCollection;

                path.Data = myPathGeometry;
            }
            else
            {
                CurrentPosition = CurrentPosition.Change(50, 30);
                var myLineSegment = new LineSegment()
                {
                    Point = CurrentPosition
                };
                MyPathFigure.Segments.Add(myLineSegment);
            }
        }
Exemple #17
0
        private UIElement GetCurvedPath(Brush brush, SweepDirection sweepDirection, Point pathPoint, Point arcPoint, Point linePoint)
        {
            var initialRect     = new RectangleGeometry(new Rect(new Size(rectWidth, rectHeight)));
            var arcPathSegments = new PathSegmentCollection
            {
                new ArcSegment
                {
                    Point = arcPoint, Size = arcSize, SweepDirection = sweepDirection
                },
                new LineSegment {
                    Point = linePoint
                }
            };

            var arcPathFigures = new PathFigureCollection
            {
                new PathFigure
                {
                    StartPoint = pathPoint,
                    Segments   = arcPathSegments
                }
            };
            var arcPath = new PathGeometry
            {
                Figures = arcPathFigures
            };

            return(new Path
            {
                Data = new CombinedGeometry(GeometryCombineMode.Exclude, initialRect, arcPath),
                Fill = brush
            });
        }
        internal void DrawBezier(double thickness, Color color, Point startPoint, Point controlPoint, Point endPoint)
        {
            PathFigure myPathFigure = new PathFigure();
            myPathFigure.StartPoint = startPoint;

            BezierSegment myBezierSegment = new BezierSegment(startPoint, endPoint, controlPoint, true);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
            myPathSegmentCollection.Add(myBezierSegment);

            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();
            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();
            myPathGeometry.Figures = myPathFigureCollection;

            DrawingContext drawingContext = drawingVisual.RenderOpen();

            mySolidColorBrush.Color = color;
            //ApplyColortool(color.A);
            pen.Brush = mySolidColorBrush;
            pen.Thickness = thickness;

            drawingContext.DrawGeometry(null, pen, myPathGeometry);

            drawingContext.Close();
            image.Render(drawingVisual);
        }
Exemple #19
0
        private void Path_Click(object sender, RoutedEventArgs e)
        {
            path.Stroke          = Brushes.Black;
            path.StrokeThickness = 1;
            BezierSegment         bezierCurve1 = new BezierSegment(new Point(0, 0), new Point(0, 50), new Point(50, 90), true);
            BezierSegment         bezierCurve2 = new BezierSegment(new Point(200, -70), new Point(100, 0), new Point(50, 30), true);
            PathSegmentCollection psc          = new PathSegmentCollection();

            psc.Add(bezierCurve1);
            psc.Add(bezierCurve2);
            PathFigure pf = new PathFigure();

            pf.Segments   = psc;
            pf.StartPoint = new Point(50, 30);
            PathFigureCollection pfc = new PathFigureCollection();

            pfc.Add(pf);
            PathGeometry pg = new PathGeometry();

            pg.Figures = pfc;
            GeometryGroup pathGeometryGroup = new GeometryGroup();

            pathGeometryGroup.Children.Add(pg);
            path.Data        = pathGeometryGroup;
            path.Margin      = new Thickness(480, 450, 0, 0);
            Path.MouseEnter += PaMouseEnter;
            Scene.Children.Add(path);
        }
Exemple #20
0
        public void Refresh()
        {
            var line = this;

            var pathGeometry1         = new PathGeometry();
            var pathFigureCollection1 = new PathFigureCollection();
            var pathFigure1           = new PathFigure();

            pathFigure1.IsClosed   = false;
            pathFigure1.StartPoint = new Windows.Foundation.Point(line.from_point.X, line.from_point.Y);
            pathFigureCollection1.Add(pathFigure1);
            pathGeometry1.Figures = pathFigureCollection1;

            var pathSegmentCollection1 = new PathSegmentCollection();
            var pathSegment1           = new BezierSegment();

            pathSegment1.Point1 = new Point(line.from_point.X + 200, line.from_point.Y);
            pathSegment1.Point2 = new Point(line.to_point.X - 200, line.to_point.Y);
            pathSegment1.Point3 = new Point(line.to_point.X, line.to_point.Y);
            pathSegmentCollection1.Add(pathSegment1);

            pathFigure1.Segments = pathSegmentCollection1;


            line.UIPath.Data = pathGeometry1;
        }
Exemple #21
0
        public void Draw(EasingFunctionBase easingFunction)
        {
            canvas1.Children.Clear();


            PathSegmentCollection pathSegments = new PathSegmentCollection();

            for (double i = 0; i < 1; i += _samplingInterval)
            {
                double x = i * canvas1.Width;
                double y = easingFunction.Ease(i) * canvas1.Height;

                var segment = new LineSegment();
                segment.Point = new Point(x, y);

                pathSegments.Add(segment);
            }
            var p = new Path();

            p.Stroke          = new SolidColorBrush(Colors.Black);
            p.StrokeThickness = 3;
            PathFigureCollection figures = new PathFigureCollection();

            figures.Add(new PathFigure()
            {
                Segments = pathSegments
            });
            p.Data = new PathGeometry()
            {
                Figures = figures
            };
            canvas1.Children.Add(p);
        }
        public CachingTest()
        {
            InitializeComponent();

            var pathGeometry = new PathGeometry();
            var pathFigure   = new PathFigure {
                StartPoint = new Point(0, 0)
            };
            var pathSegmentCollection = new PathSegmentCollection();

            var maxHeight = (int)Height;
            var maxWidth  = (int)Width;
            var rand      = new Random();

            for (var i = 0; i < 500; i++)
            {
                var newSegment = new LineSegment {
                    Point = new Point(rand.Next(0, maxWidth), rand.Next(0, maxHeight))
                };
                pathSegmentCollection.Add(newSegment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);

            BackgroundPath.Data = pathGeometry;
        }
Exemple #23
0
        public BezierCurve()
        {
            MinHeight       = 2;
            MinWidth        = 100;
            _transform      = new TranslateTransform();
            RenderTransform = _transform;
            _bezierSegment  = new BezierSegment();

            var segments = new PathSegmentCollection
            {
                _bezierSegment
            };

            var pathFigure = new PathFigure
            {
                Segments = segments
            };

            var figures = new PathFigureCollection
            {
                pathFigure
            };

            _beziergGeometry = new PathGeometry
            {
                Figures = figures
            };
        }
        /// <summary>
        /// 绘制指定的 easing 的曲线图
        /// </summary>
        private void DrawEasingGraph(EasingFunctionBase easingFunction)
        {
            graph.Children.Clear();

            Path         path         = new Path();
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure   pathFigure   = new PathFigure()
            {
                StartPoint = new Point(0, 0)
            };
            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            // 0 - 1 之间每隔 0.005 计算出一段 LineSegment,用于显示此 0.005 时间段内的缓动曲线
            for (double i = 0; i < 1; i += 0.005)
            {
                double x = i * graphContainer.Width;
                double y = easingFunction.Ease(i) * graphContainer.Height;

                LineSegment segment = new LineSegment();
                segment.Point = new Point(x, y);
                pathSegmentCollection.Add(segment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);
            path.Data            = pathGeometry;
            path.Stroke          = new SolidColorBrush(Colors.Black);
            path.StrokeThickness = 1;

            graph.Children.Add(path);
        }
Exemple #25
0
        public Path Draw(double X, double Y)
        {
            Path path = new Path();

            Canvas.SetTop(path, Y);
            Canvas.SetLeft(path, X);
            //Make Geometry
            _arcSeg = new ArcSegment(new Point(X + 800, Y + 800), new Size(1000, 2000), 0.0, true, SweepDirection.Clockwise, true);
            PathSegmentCollection psc = new PathSegmentCollection()
            {
                _arcSeg
            };

            _pathFig = new PathFigure(new Point(X, Y), psc, false);
            PathFigureCollection pfc = new PathFigureCollection()
            {
                _pathFig
            };
            PathGeometry pgeo = new PathGeometry(pfc);

            path.Data = pgeo;

            path.StrokeThickness = 200;
            path.Fill            = Brushes.White;
            path.Stroke          = Brushes.Black;

            return(path);
        }
        private Path SimpleLine()
        {
            // <SnippetPathGeometryLineSegmentInline>
            PathFigure myPathFigure = new PathFigure();

            myPathFigure.StartPoint = new Point(10, 50);

            LineSegment myLineSegment = new LineSegment();

            myLineSegment.Point = new Point(200, 70);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            myPathSegmentCollection.Add(myLineSegment);

            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = myPathFigureCollection;

            Path myPath = new Path();

            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;
            myPath.Data            = myPathGeometry;
            // </SnippetPathGeometryLineSegmentInline>
            return(myPath);
        }
            private Geometry GetDefaultGlyph()
            {
                double x1 = m_columnHeader.ActualWidth - 13;
                double x2 = x1 + 10;
                double x3 = x1 + 5;
                double y1 = m_columnHeader.ActualHeight / 2 - 3;
                double y2 = y1 + 5;

                if (m_direction == ListSortDirection.Ascending)
                {
                    double tmp = y1;
                    y1 = y2;
                    y2 = tmp;
                }

                PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

                pathSegmentCollection.Add(new LineSegment(new Point(x2, y1), true));
                pathSegmentCollection.Add(new LineSegment(new Point(x3, y2), true));

                PathFigure pathFigure = new PathFigure(
                    new Point(x1, y1),
                    pathSegmentCollection,
                    true);

                PathFigureCollection pathFigureCollection = new PathFigureCollection {
                    pathFigure
                };
                PathGeometry pathGeometry = new PathGeometry(pathFigureCollection);

                return(pathGeometry);
            }
        private Path SimpleQuadraticBezierLine()
        {
            // <Snippet34>
            PathFigure myPathFigure = new PathFigure();

            myPathFigure.StartPoint = new Point(10, 100);

            QuadraticBezierSegment myQuadraticBezierSegment = new QuadraticBezierSegment();

            myQuadraticBezierSegment.Point1 = new Point(200, 200);
            myQuadraticBezierSegment.Point2 = new Point(300, 100);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            myPathSegmentCollection.Add(myQuadraticBezierSegment);

            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = myPathFigureCollection;

            Path myPath = new Path();

            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;
            myPath.Data            = myPathGeometry;
            // </Snippet34>
            return(myPath);
        }
Exemple #29
0
        public Superposition()
        {
            InitializeComponent();
                        
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure pathFigure = new PathFigure();
            
            pathFigure.StartPoint = new Point(0,0);

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            int maxHeight = (int)this.Height;
            int maxWidth = (int)this.Width;
            Random rand = new Random();
            for (int i = 0; i < 500; i++)
            {
                LineSegment newSegment = new LineSegment();
                newSegment.Point = new Point(rand.Next(0, maxWidth), rand.Next(0, maxHeight));
                pathSegmentCollection.Add(newSegment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);

            pathBackground.Data = pathGeometry;


        }
Exemple #30
0
        /// <summary>
        /// This function allows to draw the right arc of the object.
        /// </summary>
        protected void drawRightArc()
        {
            // The radius of the circumcercle.
            double radius = Math.Sqrt(height * height + width * width) / 2;

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
            PathFigure            segmentPathFigure     = new PathFigure();

            Point arcStartPoint = PointOnCircle(radius, arcRight_angleLow, new Point(x, y));
            Point arcStopPoint  = PointOnCircle(radius, arcRight_angleHigh, new Point(x, y));

            segmentPathFigure.StartPoint = arcStartPoint;

            ArcSegment arcSegment = new ArcSegment(arcStopPoint, new Size(radius, radius), 0, false, SweepDirection.Counterclockwise, true);

            pathSegmentCollection.Add(arcSegment);
            segmentPathFigure.Segments = pathSegmentCollection;
            PathFigureCollection segmentPathFigureCollection = new PathFigureCollection();

            segmentPathFigureCollection.Add(segmentPathFigure);
            PathGeometry segmentPathGeometry = new PathGeometry();

            segmentPathGeometry.Figures = segmentPathFigureCollection;

            // Set up the segment's drawing (and hit-testing) path.
            arcRight                 = new Path();
            arcRight.Stroke          = Brushes.Black;
            arcRight.StrokeThickness = 1;
            arcRight.Fill            = Brushes.Transparent;
            arcRight.Data            = segmentPathGeometry;
            Canvas.SetLeft(arcRight, 0);
            Canvas.SetTop(arcRight, 0);
            Canvas.SetZIndex(arcRight, 1);
            Canvas.Children.Add(arcRight);
        }
Exemple #31
0
        /// <summary>
        /// 画直线段
        /// </summary>
        /// <param name="points"></param>
        /// <param name="clr"></param>
        /// <returns></returns>
        private static Path DrawLine(List <Point> points, Color clr)
        {
            PathSegmentCollection segments = new PathSegmentCollection();

            for (int i = 1; i < points.Count; i++)
            {
                segments.Add(new LineSegment(points[i], true));
            }

            Path segment = new Path()
            {
                StrokeLineJoin  = PenLineJoin.Round,
                Stroke          = new SolidColorBrush(clr),
                Fill            = new SolidColorBrush(clr),
                Opacity         = 0.05,
                StrokeThickness = 0.25,
                Data            = new PathGeometry()
                {
                    Figures = new PathFigureCollection()
                    {
                        new PathFigure()
                        {
                            IsClosed = true, IsFilled = true, StartPoint = points[0], Segments = segments
                        }
                    }
                }
            };

            return(segment);
        }
        public CachingTest()
        {
            InitializeComponent();

            PathGeometry pathGeometry = new PathGeometry();
            PathFigure   pathFigure   = new PathFigure();

            pathFigure.StartPoint = new Point(0, 0);
            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            int    maxHeight = (int)this.Height;
            int    maxWidth  = (int)this.Width;
            Random rand      = new Random();

            for (int i = 0; i < 500; i++)
            {
                LineSegment newSegment = new LineSegment();
                newSegment.Point = new Point(rand.Next(0, maxWidth), rand.Next(0, maxHeight));
                pathSegmentCollection.Add(newSegment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);

            pathBackground.Data = pathGeometry;
        }
Exemple #33
0
        /// <summary>
        /// Although not called for in the standard, some styles could benefit from the use of splines.
        /// This method creates a set of splines passing through the user-specified coordinates.
        /// These computations are in the ResourceDictionary space.
        /// </summary>
        /// <param name="count">
        /// The number of user-specified vertices.
        /// </param>
        /// <param name="pointAnchors">
        /// The array of user-specified vertices.
        /// </param>
        /// <param name="pointCp1">
        /// The first set of control points.
        /// </param>
        /// <param name="pointCp2">
        /// The second set of control points.
        /// </param>
        /// <param name="isClosed">
        /// Whether or not the curve is closed.
        /// </param>
        /// <returns>
        /// The PathSegmentCollection representing splines passing through user-specified vertices.
        /// </returns>
        private static PathSegmentCollection GenerateBezierSegments(
            int count,
            IList <Point> pointAnchors,
            IList <Point> pointCp1,
            IList <Point> pointCp2,
            bool isClosed)
        {
            var segments = new PathSegmentCollection();

            for (var i = 1; i < count; ++i)
            {
                segments.Add(
                    new BezierSegment
                {
                    Point1 = pointCp1[i - 1],
                    Point2 = pointCp2[i],
                    Point3 = pointAnchors[i]
                });
            }

            if (isClosed)
            {
                segments.Add(
                    new BezierSegment
                {
                    Point1 = pointCp1[pointCp1.Count - 1],
                    Point2 = pointCp2[0],
                    Point3 = pointAnchors[0]
                });
            }

            return(segments);
        }
Exemple #34
0
        public static PathGeometry GetTrianglePathGeometry(Point[] pts)
        {
            System.Windows.Media.LineSegment lineSeg0 = new System.Windows.Media.LineSegment(pts[1], true);
            System.Windows.Media.LineSegment lineSeg1 = new System.Windows.Media.LineSegment(pts[2], true);
            System.Windows.Media.LineSegment lineSeg2 = new System.Windows.Media.LineSegment(pts[0], true);

            PathSegmentCollection pathsegmentCollection = new PathSegmentCollection();

            pathsegmentCollection.Add(lineSeg0);
            pathsegmentCollection.Add(lineSeg1);
            pathsegmentCollection.Add(lineSeg2);

            PathFigure pathFigure = new PathFigure();

            pathFigure.StartPoint = pts[0];
            pathFigure.Segments   = pathsegmentCollection;

            PathFigureCollection pathFigureCollection = new PathFigureCollection();

            pathFigureCollection.Add(pathFigure);

            PathGeometry pathGeometry = new PathGeometry();

            pathGeometry.Figures = pathFigureCollection;

            return(pathGeometry);
        }
Exemple #35
0
        public static PathGeometry GetPathGeometryFromPoints(System.Windows.Point startPoint, params Point[] otherPoints)
        {
            Debug.Assert(otherPoints != null);

            Int32 iOtherPoints = otherPoints.Length;

            Debug.Assert(iOtherPoints > 0);

            PathFigure oPathFigure = new PathFigure()
            {
                StartPoint = startPoint
            };

            PathSegmentCollection oPathSegmentCollection =
                new PathSegmentCollection(iOtherPoints);

            for (Int32 i = 0; i < iOtherPoints; i++)
            {
                oPathSegmentCollection.Add(
                    new LineSegment(otherPoints[i], true));
            }

            oPathFigure.Segments = oPathSegmentCollection;
            oPathFigure.IsClosed = true;
            GeometryHelper.TryFreeze(oPathFigure);

            PathGeometry oPathGeometry = new PathGeometry();

            oPathGeometry.Figures.Add(oPathFigure);
            GeometryHelper.TryFreeze(oPathGeometry);

            return(oPathGeometry);
        }
Exemple #36
0
        public void Sample()
        {
            PathFigure myPathFigure = new PathFigure();

            myPathFigure.StartPoint = new Point(10, 50);

            LineSegment myLineSegment = new LineSegment();

            myLineSegment.Point = new Point(200, 70);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            myPathSegmentCollection.Add(myLineSegment);

            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = myPathFigureCollection;

            Path myPath = new Path();

            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;
            myPath.Data            = myPathGeometry;
        }
Exemple #37
0
        public override Path getRendering()
        {
            PathFigure myPathFigure = new PathFigure();

            myPathFigure.StartPoint = points[0];

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            for (int i = 1; i < points.Count; i++)
            {
                LineSegment myLineSegment = new LineSegment();
                myLineSegment.Point = points[i];
                myPathSegmentCollection.Add(myLineSegment);
            }
            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = myPathFigureCollection;

            Path            myPath = new Path();
            SolidColorBrush scb    = new SolidColorBrush(this.getColor());

            myPath.Stroke          = scb;
            myPath.StrokeThickness = this.getThickness();
            myPath.Data            = myPathGeometry;
            return(myPath);
        }
Exemple #38
0
        public static PathFigure GetPathFigureFromPoints(Point startPoint, params Point[] otherPoints)
        {
            var oPathFigure = new PathFigure()
            {
                StartPoint = startPoint
            };
            var oPathSegmentCollection = new PathSegmentCollection();

            foreach (var item in otherPoints)
            {
                oPathSegmentCollection.Add(new LineSegment
                {
                    Point = item,
#if WPF
                    IsStroked = true
#endif
                });
            }


            oPathFigure.Segments = oPathSegmentCollection;
            oPathFigure.IsClosed = true;
#if WPF
            TryFreeze(oPathFigure);
#endif
            return(oPathFigure);
        }
        public Path CreatePath(Point location, double angle, double radius, double innerRadius, Brush brush)
        {
            var isLargeArc = angle > FULL_ARC / 2;

            var path          = new Path();
            var segments      = new PathSegmentCollection();
            var arcPoint      = ConvertRadianToCartesian(angle, radius);
            var innerArcPoint = ConvertRadianToCartesian(angle, innerRadius);

            segments.Add(new LineSegment(new Point(location.X, location.Y - radius), false));
            segments.Add(new ArcSegment(new Point(location.X + arcPoint.X, location.Y + arcPoint.Y), new Size(radius, radius), 0, isLargeArc, SweepDirection.Clockwise, false));
            segments.Add(new LineSegment(new Point(location.X + innerArcPoint.X, location.Y + innerArcPoint.Y), false));
            segments.Add(new ArcSegment(new Point(location.X, location.Y - innerRadius), new Size(innerRadius, innerRadius), 0, isLargeArc, SweepDirection.Counterclockwise, false));

            var figure = new PathFigure(location, segments, true);

            path.Data = new PathGeometry {
                Figures = new PathFigureCollection {
                    figure
                }
            };

            path.Fill = brush;
            return(path);
        }
Exemple #40
0
 public static PathSegmentCollection Clone(this PathSegmentCollection source)
 {
     var result = new PathSegmentCollection();
     foreach (var pathSegment in source)
     {
         var line = pathSegment as LineSegment;
         result.Add(new LineSegment { Point = line.Point });
     }
     return result;
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     var ps = new PathSegmentCollection(4);
     ContentPresenter cp = (ContentPresenter)value;
     double h = cp.ActualHeight > 10 ? 1.4 * cp.ActualHeight : 10;
     double w = cp.ActualWidth > 10 ? 1.25 * cp.ActualWidth : 10;
     ps.Add(new LineSegment(new Point(1, 0.7 * h), true));
     ps.Add(new BezierSegment(new Point(1, 0.9 * h), new Point(0.1 * h, h), new Point(0.3 * h, h), true));
     ps.Add(new LineSegment(new Point(w, h), true));
     ps.Add(new BezierSegment(new Point(w + 0.6 * h, h), new Point(w + h, 0), new Point(w + h * 1.3, 0), true));
     return ps;
 }
        /// <summary>
        /// Converts a value.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>A converted value. If the method returns null, the valid null value is used.</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var cp = (FrameworkElement)value;
            double h = cp.ActualHeight > 10 ? 1.4 * cp.ActualHeight : 10;
            double w = cp.ActualWidth > 10 ? 1.25 * cp.ActualWidth : 10;
            PathSegmentCollection ps = new PathSegmentCollection(4)
            {
                new LineSegment(new Point(1, 0.7 * h), true),
                new BezierSegment(new Point(1, 0.9 * h), new Point(0.1 * h, h), new Point(0.3 * h, h), true),
                new LineSegment(new Point(w, h), true),
                new BezierSegment(new Point(w + (0.6 * h), h), new Point(w + h, 0), new Point(w + (h * 1.3), 0), true)
            };

            return ps;
        }
Exemple #43
0
        public static PathGeometry GenerateBezierCurve(Point[] points)
        {
            PathFigure pathFigure = new PathFigure();
            PointCollection pointCollection = new PointCollection(points.Length);
            pathFigure.StartPoint = new Point(points[0].X, points[0].Y);

            PathGeometry myPathGeometry = new PathGeometry();
            PathSegment pathSegment;

            if (points.Length == 2)
            {
                pathSegment = new LineSegment();
                ((LineSegment)pathSegment).Point = new Point(points[1].X, points[1].Y);
            }
            else if (points.Length == 3)
            {
                pathSegment = new QuadraticBezierSegment();
                ((QuadraticBezierSegment)pathSegment).Point1 = new Point(points[1].X, points[1].Y);
                ((QuadraticBezierSegment)pathSegment).Point2 = new Point(points[2].X, points[2].Y);
            }
            else if (points.Length == 4)
            {
                for (int i = 1; i < points.Length; i++)
                {
                    pointCollection.Add(points[i]);
                }

                pathSegment = new PolyBezierSegment();
                ((PolyBezierSegment)pathSegment).Points = pointCollection;
            }
            else
            {
                return null;
            }

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
            pathSegmentCollection.Add(pathSegment);

            pathFigure.Segments = pathSegmentCollection;

            PathFigureCollection pathFigureCollection = new PathFigureCollection();
            pathFigureCollection.Add(pathFigure);

            myPathGeometry.Figures = pathFigureCollection;

            return myPathGeometry;
        }
        public PointOfViewIndicator()
        {
            _activePositionBrush = Brushes.Red;
            _lineBrush = Brushes.DarkGray;
            _linePen = new Pen(_lineBrush, 1d);

            PathSegmentCollection segments = new PathSegmentCollection(4);
            segments.Add(new LineSegment(new Point(0, 10), false));
            segments.Add(new LineSegment(new Point(5, 0), false));
            segments.Add(new LineSegment(new Point(10, 10), false));
            segments.Add(new LineSegment(new Point(5, 5), false));

            PathFigureCollection figures = new PathFigureCollection();
            figures.Add(new PathFigure(new Point(5, 5), segments, true));

            _arrowPath = new PathGeometry(figures);
        }
        public Path Draw(double X, double Y)
        {
            Path path = new Path();
            Canvas.SetTop(path, Y);
            Canvas.SetLeft(path, X);
            //Make Geometry
            _arcSeg = new ArcSegment(new Point(X+800, Y+800), new Size(1000, 2000), 0.0, true, SweepDirection.Clockwise, true);
            PathSegmentCollection psc = new PathSegmentCollection(){_arcSeg};
            _pathFig = new PathFigure(new Point(X, Y), psc, false);
            PathFigureCollection pfc = new PathFigureCollection(){_pathFig};
            PathGeometry pgeo = new PathGeometry(pfc);
            path.Data = pgeo;

            path.StrokeThickness = 200;
            path.Fill = Brushes.White;
            path.Stroke = Brushes.Black;

            return path;
        }
Exemple #46
0
        public Path CreatePath(Point location, double angle, double radius, double innerRadius, Brush brush)
        {
            var isLargeArc = angle > FULL_ARC / 2;

            var path = new Path();
            var segments = new PathSegmentCollection();
            var arcPoint = ConvertRadianToCartesian(angle, radius);
            var innerArcPoint = ConvertRadianToCartesian(angle, innerRadius);

            segments.Add(new LineSegment(new Point(location.X, location.Y - radius), false));
            segments.Add(new ArcSegment(new Point(location.X + arcPoint.X, location.Y + arcPoint.Y), new Size(radius, radius), 0, isLargeArc, SweepDirection.Clockwise, false));
            segments.Add(new LineSegment(new Point(location.X + innerArcPoint.X, location.Y + innerArcPoint.Y), false));
            segments.Add(new ArcSegment(new Point(location.X, location.Y - innerRadius), new Size(innerRadius, innerRadius), 0, isLargeArc, SweepDirection.Counterclockwise, false));

            var figure = new PathFigure(location, segments, true);
            path.Data = new PathGeometry { Figures = new PathFigureCollection { figure } };

            path.Fill = brush;
            return path;
        }
        private static PathSegmentCollection PointsAroundWidget(List<System.Windows.Point> pointlist)
        {
            PathSegmentCollection collection = new PathSegmentCollection();

            int index = 0;
            collection.Add(new ArcSegment(pointlist[index], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));


            index = (index + 1) % pointlist.Count;
            collection.Add(new ArcSegment(pointlist[index], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));


            index = (index + 1) % pointlist.Count;
            collection.Add(new ArcSegment(pointlist[index], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));


            index = (index + 1) % pointlist.Count;
            collection.Add(new ArcSegment(pointlist[index], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));

            return collection;
        }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     PathSegmentCollection retVal = new PathSegmentCollection();
     PointCollection pointCollection = value as PointCollection;
     if (RoundRadius > 0)
     {
         if (pointCollection != null && pointCollection.Count > 0)
         {
             retVal.Add(new LineSegment(pointCollection[0], true));
             double curSegmentArcUsed = 0;
             for (int i = 1; i < pointCollection.Count - 1; i++)
             {
                 double dist1 = DesignerGeometryHelper.DistanceBetweenPoints(pointCollection[i - 1], pointCollection[i]);
                 double dist2 = DesignerGeometryHelper.DistanceBetweenPoints(pointCollection[i], pointCollection[i + 1]);
                 if (dist1 - curSegmentArcUsed > RoundRadius &&
                     dist2 > RoundRadius)
                 {
                     //build rounded arc at line join.
                     curSegmentArcUsed = RoundRadius;
                     Vector firstSegmentPointingVector = new Vector(pointCollection[i].X - pointCollection[i - 1].X, pointCollection[i].Y - pointCollection[i - 1].Y);
                     Vector secondSegmentPointingVector = new Vector(pointCollection[i + 1].X - pointCollection[i].X, pointCollection[i + 1].Y - pointCollection[i].Y);
                     firstSegmentPointingVector.Normalize();
                     secondSegmentPointingVector.Normalize();
                     Point turningPoint1 = Point.Add(pointCollection[i - 1], Vector.Multiply(dist1 - RoundRadius, firstSegmentPointingVector));
                     Point turningPoint2 = Point.Add(pointCollection[i], Vector.Multiply(RoundRadius, secondSegmentPointingVector));
                     double crossProductZ = firstSegmentPointingVector.X * secondSegmentPointingVector.Y - firstSegmentPointingVector.Y * secondSegmentPointingVector.X;
                     retVal.Add(new LineSegment(turningPoint1, true));
                     retVal.Add(new ArcSegment(turningPoint2, new Size(RoundRadius, RoundRadius), 0, false, crossProductZ > 0 ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, true));
                 }
                 else
                 {
                     curSegmentArcUsed = 0;
                     retVal.Add(new LineSegment(pointCollection[i], true));
                 }
             }
             retVal.Add(new LineSegment(pointCollection[pointCollection.Count - 1], true));
         }
     }
     return retVal;
 }
Exemple #49
0
        public void Arc(Canvas surface, double left, double top, double right, double bottom, double startArcX, double startArcY, double endArcX, double endArcY)
        {
            var arc = new Path();
            var figure = new PathFigure();
            var segments = new PathSegmentCollection();

            var center = new Point(left + ((right - left) / 2), top + ((bottom - top) / 2));
            double degrees = Math.Atan2(startArcY - center.Y, startArcX - center.X)
                            - Math.Atan2(endArcY - center.Y, endArcX - center.X);

            degrees *= 57.2957795; // Convert from radians to degrees
            bool isLargeArc = Math.Abs(degrees) > 180;

            arc.Data = new PathGeometry();

            figure.StartPoint = new Point(LtoDX(startArcX), LtoDY(startArcY));

            var segment = new ArcSegment
                              {
                                  Point = new Point(
                                      LtoDX(endArcX),
                                      LtoDY(endArcY)),
                                  Size = new Size(
                                      (LtoDX(right) - LtoDX(left)) / 2,
                                      (LtoDY(bottom) - LtoDY(top)) / 2),
                                  RotationAngle = 0,
                                  IsLargeArc = isLargeArc,
                                  SweepDirection = SweepDirection.Counterclockwise
                              };

            segments.Add(segment);

            figure.Segments = segments;
            ((PathGeometry)arc.Data).Figures.Add(figure);

            ApplyStyle(arc, false);

            surface.Children.Add(arc);
        }
        private static PathSegmentCollection PointsForTractorBeam(System.Windows.Point cursorLocation, List<System.Windows.Point> pointlist)
        {
            //Get the path that will be used to render the tractor beam.
            PathSegmentCollection collection = new PathSegmentCollection();

            //We will use the points that create the biggest angle for the tractor beam coming from the cursor.
            System.Windows.Point[] startAndEnd = PointsThatMakeBiggestAngle(cursorLocation, pointlist);

            //Make sure they are sorted by x value (the tractor beam is rendered clockwise).
            if (startAndEnd[0].X < startAndEnd[1].X)
            {
                System.Windows.Point tmp = startAndEnd[0];
                startAndEnd[0] = startAndEnd[1];
                startAndEnd[1] = tmp;
            }

            //Get the index of the start System.Windows.Point in the list of points around the widget and add it to the path.
            int index = pointlist.IndexOf(startAndEnd[0]);
            collection.Add(new ArcSegment(pointlist[index], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));


            //Get the index of the end System.Windows.Point in the list of points around the widget.
            int endIndex = pointlist.IndexOf(startAndEnd[1]);
            
            
            //Now add the System.Windows.Point that is closest to the cursor if it's not the starting or ending point.
            //This creates a wedge at the end of the tractor beam.
            System.Windows.Point closest = ClosestToCursor(cursorLocation, pointlist);
            if (closest != startAndEnd[0] && closest != startAndEnd[1])
                collection.Add(new ArcSegment(pointlist[pointlist.IndexOf(closest)], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));
            
            
            //Now add the end System.Windows.Point to the path.
            collection.Add(new ArcSegment(pointlist[endIndex], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));

            
            return collection;

        }
        /// <summary>
        /// transform a list of coordinate in a scatterviewitem
        /// </summary>
        /// <param name="coord"></param>
        public ScatterViewItem createScatterViewItem(List<int> coord)
        {
            ScatterViewItem myShape = new ScatterViewItem();
            //create the pathGeometry
            if (coord != null)
            {
                PathFigure myPathFigure = new PathFigure();
                myPathFigure.StartPoint = new Point(coord[0], coord[1]);

                PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                for (int i = 2; i < coord.Count(); i = i + 2)
                {
                    LineSegment myLineSegment = new LineSegment();
                    myLineSegment.Point = new Point(coord[i], coord[i + 1]);
                    myPathSegmentCollection.Add(myLineSegment);
                }

                myPathFigure.Segments = myPathSegmentCollection;
                PathFigureCollection myPathFigureCollection = new PathFigureCollection();
                myPathFigureCollection.Add(myPathFigure);
                PathGeometry myPathGeometry = new PathGeometry();
                myPathGeometry.Figures = myPathFigureCollection;

                //create the path
                System.Windows.Shapes.Path myPath = new System.Windows.Shapes.Path();
                myPath.Stroke = Brushes.Black;
                myPath.StrokeThickness = 1;
                myPath.Data = myPathGeometry;
                myPath.Fill = new SolidColorBrush(Colors.Blue);

                //create the scatterViewItem
                myShape.Content = myPath;
                myShape.Width = this.max(coord);
                myShape.Height = this.max(coord);
            }

            return myShape;
        }
        public static Geometry BorderFromPoints(double haw, double hah, double taw,double tah,double arcvalue)
        {
            //double Margin = 10;
            //double before = Margin + arcvalue;
            double startheaderxmargin = 20;
            double yupmargin = hah / 2;
            double ymargin = 5;
            double xmargin = 2;

            PathFigure myPathFigure = new PathFigure();
            myPathFigure.StartPoint = new Point(haw + startheaderxmargin, yupmargin);

            Size ArcSize = new Size(arcvalue, arcvalue);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
            myPathSegmentCollection.Add(new LineSegment(new Point(taw - arcvalue, yupmargin), true));
            myPathSegmentCollection.Add(new ArcSegment(new Point(taw - xmargin, yupmargin + arcvalue), ArcSize, 90, false, SweepDirection.Clockwise, true));

            myPathSegmentCollection.Add(new LineSegment(new Point(taw - xmargin, tah - arcvalue - ymargin), true));
            myPathSegmentCollection.Add(new ArcSegment(new Point(taw - arcvalue - xmargin, tah - ymargin), ArcSize, 90, false, SweepDirection.Clockwise, true));

            myPathSegmentCollection.Add(new LineSegment(new Point(arcvalue, tah - ymargin), true));
            myPathSegmentCollection.Add(new ArcSegment(new Point(0, tah - ymargin - arcvalue), ArcSize, 90, false, SweepDirection.Clockwise, true));

            myPathSegmentCollection.Add(new LineSegment(new Point(0, arcvalue + yupmargin), true));
            myPathSegmentCollection.Add(new ArcSegment(new Point(arcvalue / 2, yupmargin + arcvalue / 2), ArcSize, 45, false, SweepDirection.Clockwise, true));
    
            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();
            myPathFigureCollection.Add(myPathFigure);

            PathGeometry pg = new PathGeometry();
            pg.Figures = myPathFigureCollection;
            return pg;
        }
    GetPathGeometryFromPoints
    (
        System.Windows.Point startPoint,
        params Point [] otherPoints
    )
    {
        Debug.Assert(otherPoints != null);

        Int32 iOtherPoints = otherPoints.Length;

        Debug.Assert(iOtherPoints > 0);

        PathFigure oPathFigure = new PathFigure();

        oPathFigure.StartPoint = startPoint;

        PathSegmentCollection oPathSegmentCollection =
            new PathSegmentCollection(iOtherPoints);

        for (Int32 i = 0; i < iOtherPoints; i++)
        {
            oPathSegmentCollection.Add(
                new LineSegment(otherPoints[i], true) );
        }

        oPathFigure.Segments = oPathSegmentCollection;
        oPathFigure.IsClosed = true;
        WpfGraphicsUtil.FreezeIfFreezable(oPathFigure);

        PathGeometry oPathGeometry = new PathGeometry();

        oPathGeometry.Figures.Add(oPathFigure);
        WpfGraphicsUtil.FreezeIfFreezable(oPathGeometry);

        return (oPathGeometry);
    }
        // Called when skeleton is not being tracked
        public void Reset()
        {
            this.currentSkeleton = null;
            this.lastPoint = new SkeletonPoint();
            this.pointList = new List<Point>();
            this.trajectoryPathSegments = null;
            this.trajectoryPathFigure = null;
            this.trajectoryPathFigureCollection = null;
            this.trajectoryPathGeometry = null;
            this.Distance = 0.0;
            this.velocity = 0.0;
            this.Direction = "NA";
            this.TrackingAngle = Properties.Settings.Default.KinectAngle;

            if (Settings.Default.UseAngle)
            {
                this.AngleProjectionFactorX = (float)Math.Cos((TrackingAngle * Math.PI) / 180);
                this.AngleProjectionFactorZ = (float)Math.Sin((TrackingAngle * Math.PI) / 180);
            }
            else
            {
                this.AngleProjectionFactorX = 1;
                this.AngleProjectionFactorZ = 1;
            }

            this.FrameSub = Properties.Settings.Default.TrajectorySubsample;
            this.milliseconds = 0;
            this.lastmilliseconds = 0;

            this.kalmanFilter = new Kalman();

            InvalidateVisual();
        }
        /// <summary>
        /// Draw the hatches and the transparent area where isn't covering the elements.
        /// </summary>
        /// <param name="drawingContext"></param>
        private void DrawBackgound(DrawingContext drawingContext)
        {
            PathGeometry hatchGeometry = null;
            Geometry rectGeometry = null;

            int count = _elementsBounds.Count;
            if ( count != 0 )
            {
                // Create a union collection of the element regions.
                for ( int i = 0; i < count; i++ )
                {
                    Rect hatchRect = _elementsBounds[i];

                    if ( hatchRect.IsEmpty )
                    {
                        continue;
                    }

                    hatchRect.Inflate(HatchBorderMargin / 2, HatchBorderMargin / 2);

                    if ( hatchGeometry == null )
                    {
                        PathFigure path = new PathFigure();
                        path.StartPoint = new Point(hatchRect.Left, hatchRect.Top);

                        PathSegmentCollection segments = new PathSegmentCollection();
                        
                        PathSegment line = new LineSegment(new Point(hatchRect.Right, hatchRect.Top), true); 
                        line.Freeze();
                        segments.Add(line);
                        
                        line = new LineSegment(new Point(hatchRect.Right, hatchRect.Bottom), true); 
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Bottom), true);
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Top), true);
                        line.Freeze();
                        segments.Add(line);

                        segments.Freeze();
                        path.Segments = segments;

                        path.IsClosed = true;
                        path.Freeze();

                        hatchGeometry = new PathGeometry();
                        hatchGeometry.Figures.Add(path);
                    }
                    else
                    {
                        rectGeometry = new RectangleGeometry(hatchRect);
                        rectGeometry.Freeze();

                        hatchGeometry = Geometry.Combine(hatchGeometry, rectGeometry, GeometryCombineMode.Union, null);
                    }
                }
            }

            // Then, create a region which equals to "SelectionFrame - element1 bounds - element2 bounds - ..."
            GeometryGroup backgroundGeometry = new GeometryGroup( );
            GeometryCollection geometryCollection = new GeometryCollection();

            // Add the entile rectanlge to the group.
            rectGeometry = new RectangleGeometry(new Rect(0, 0, RenderSize.Width, RenderSize.Height));
            rectGeometry.Freeze();
            geometryCollection.Add(rectGeometry);

            // Add the union of the element rectangles. Then the group will do oddeven operation.
            Geometry outlineGeometry = null;

            if ( hatchGeometry != null )
            {
                hatchGeometry.Freeze();

                outlineGeometry = hatchGeometry.GetOutlinedPathGeometry();
                outlineGeometry.Freeze();
                if ( count == 1 && ((InkCanvasInnerCanvas)AdornedElement).InkCanvas.GetSelectedStrokes().Count == 0 )
                {
                    geometryCollection.Add(outlineGeometry);
                }
            }

            geometryCollection.Freeze();
            backgroundGeometry.Children = geometryCollection;
            backgroundGeometry.Freeze();

            // Then, draw the region which may contain holes so that the elements cannot be covered.
            // After that, the underneath elements can receive the messages.
#if DEBUG_OUTPUT
            // Draw the debug feedback
            drawingContext.DrawGeometry(new SolidColorBrush(Color.FromArgb(128, 255, 255, 0)), null, backgroundGeometry);
#else
            drawingContext.DrawGeometry(Brushes.Transparent, null, backgroundGeometry);
#endif

            // At last, draw the hatch borders
            if ( outlineGeometry != null )
            {
                drawingContext.DrawGeometry(null, _hatchPen, outlineGeometry);
            }
        }
Exemple #56
0
 public void AddPixelPair(int x, int y)
 {
     if (!this.start.HasValue)
         this.start = new Point(x, y);
     else {
         if (this.segments == null)
             this.segments = new PathSegmentCollection();
         this.segments.Add(new LineSegment(new Point(x, y), true));
     }
 }
Exemple #57
0
 public void StartOver(int numlocations)
 {
     this.start = null;
     this.segments = null;
 }
Exemple #58
0
        public override void Plot(bool animate = true)
        {
            if (Visibility != Visibility.Visible) return;
            var chart = Chart as RadarChart;
            if (chart == null) return;
            var alpha = 360 / chart.Max.X;

            var pf = new PathFigure();
            var segments = new PathSegmentCollection();
            var l = 0d;

            Point? p2 = null;

            if (!Values.Points.Any()) return;
            var lastPoint = Values.Points.Last();
            var fisrtPoint = Values.Points.First();
            foreach (var point in Values.Points)
            {
                var r1 = point != lastPoint
                    ? chart.ToChartRadius(point.Y)
                    : chart.ToChartRadius(fisrtPoint.Y);
                if (point == fisrtPoint)
                    pf.StartPoint = new Point(
                        chart.ActualWidth/2 + Math.Sin(alpha*point.X*(Math.PI/180))*r1,
                        chart.ActualHeight/2 - Math.Cos(alpha*point.X*(Math.PI/180))*r1);
                else
                    segments.Add(new LineSegment
                    {
                        Point = new Point
                        {
                            X = chart.ActualWidth/2 + Math.Sin(alpha*point.X*(Math.PI/180))*r1,
                            Y = chart.ActualHeight/2 - Math.Cos(alpha*point.X*(Math.PI/180))*r1
                        }
                    });

                var p1 = new Point(chart.ActualWidth/2 + Math.Sin(alpha*point.X*(Math.PI/180))*r1,
                    chart.ActualHeight/2 - Math.Cos(alpha*point.X*(Math.PI/180))*r1);
                if (p2 != null)
                {
                    l += Math.Sqrt(
                        Math.Pow(Math.Abs(p1.X - p2.Value.X), 2) +
                        Math.Pow(Math.Abs(p1.Y - p2.Value.Y), 2)
                        );
                }
                p2 = p1;

                if (point == lastPoint) continue;

                var r = new Rectangle
                {
                    Fill = Brushes.Transparent,
                    Width = 40,
                    Height = 40
                };
                var e = new Ellipse
                {
                    Width = PointRadius*2,
                    Height = PointRadius*2,
                    Fill = Stroke,
                    Stroke = new SolidColorBrush {Color = Chart.PointHoverColor},
                    StrokeThickness = 2
                };

                r.MouseEnter += chart.DataMouseEnter;
                r.MouseLeave += chart.DataMouseLeave;
                r.MouseDown += chart.DataMouseDown;
                chart.Canvas.Children.Add(r);
                Shapes.Add(r);
                chart.HoverableShapes.Add(new HoverableShape
                {
                    Series = this,
                    Shape = r,
                    Value = point,
                    Target = e
                });

                Shapes.Add(e);
                chart.Canvas.Children.Add(e);
                Panel.SetZIndex(r, int.MaxValue);

                Canvas.SetLeft(e, p1.X - e.Width/2);
                Canvas.SetTop(e, p1.Y - e.Height/2);
                Panel.SetZIndex(e, 2);

                Canvas.SetLeft(r, p1.X - r.Width/2);
                Canvas.SetTop(r, p1.Y - r.Height/2);
                Panel.SetZIndex(r, int.MaxValue);

                if (!chart.DisableAnimation && animate)
                {
                    var topAnim = new DoubleAnimation
                    {
                        From = chart.ActualHeight/2,
                        To = p1.Y - e.Height/2,
                        Duration = TimeSpan.FromMilliseconds(300)
                    };
                    e.BeginAnimation(Canvas.TopProperty, topAnim);
                    var leftAnim = new DoubleAnimation
                    {
                        From = chart.ActualWidth/2,
                        To = p1.X - e.Width/2,
                        Duration = TimeSpan.FromMilliseconds(300)
                    };
                    e.BeginAnimation(Canvas.LeftProperty, leftAnim);
                }

            }

            pf.Segments = segments;
            var g = new PathGeometry
            {
                Figures = new PathFigureCollection(new List<PathFigure>
                {
                    pf
                })
            };

            var path = new Path
            {
                Stroke = Stroke,
                StrokeThickness = StrokeThickness,
                Data = g,
                StrokeEndLineCap = PenLineCap.Round,
                StrokeStartLineCap = PenLineCap.Round,
                Fill = Fill,
                StrokeDashOffset = l,
                StrokeDashArray = new DoubleCollection { l, l }
            };

            var draw = new DoubleAnimationUsingKeyFrames
            {
                BeginTime = TimeSpan.FromSeconds(0),
                KeyFrames = new DoubleKeyFrameCollection
                {
                    new SplineDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.FromMilliseconds(1),
                        Value = l
                    },
                    new SplineDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.FromMilliseconds(750),
                        Value = 0
                    }
                }
            };
            Storyboard.SetTarget(draw, path);
            Storyboard.SetTargetProperty(draw, new PropertyPath(Shape.StrokeDashOffsetProperty));
            var sbDraw = new Storyboard();
            sbDraw.Children.Add(draw);
            var animated = false;
            if (!chart.DisableAnimation)
            {
                if (animate)
                {
                    sbDraw.Begin();
                    animated = true;
                }
            }
            if (!animated) path.StrokeDashOffset = 0;

            chart.Canvas.Children.Add(path);
            Shapes.Add(path);
        }
        /// <summary>
        /// Creates a border geometry with a 'pointer'.
        /// </summary>
        /// <param name="ha">The horizontal alignment.</param>
        /// <param name="va">The vertical alignment.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="margin">The margin.</param>
        /// <returns>The border geometry.</returns>
        private Geometry CreatePointerBorderGeometry(
            System.Windows.HorizontalAlignment ha, System.Windows.VerticalAlignment va, double width, double height, out Thickness margin)
        {
            Point[] points = null;
            double m = this.Distance;
            margin = new Thickness();

            if (ha == System.Windows.HorizontalAlignment.Center && va == System.Windows.VerticalAlignment.Bottom)
            {
                double x0 = 0;
                double x1 = width;
                double x2 = (x0 + x1) / 2;
                double y0 = 0;
                double y1 = height;
                margin = new Thickness { Bottom = m };
                points = new[]
                    {
                        new Point(x0, y0), new Point(x1, y0), new Point(x1, y1), new Point(x2 + (m / 2), y1),
                        new Point(x2, y1 + m), new Point(x2 - (m / 2), y1), new Point(x0, y1)
                    };
            }

            if (ha == System.Windows.HorizontalAlignment.Center && va == System.Windows.VerticalAlignment.Top)
            {
                double x0 = 0;
                double x1 = width;
                double x2 = (x0 + x1) / 2;
                double y0 = m;
                double y1 = m + height;
                margin = new Thickness { Top = m };
                points = new[]
                    {
                        new Point(x0, y0), new Point(x2 - (m / 2), y0), new Point(x2, 0), new Point(x2 + (m / 2), y0),
                        new Point(x1, y0), new Point(x1, y1), new Point(x0, y1)
                    };
            }

            if (ha == System.Windows.HorizontalAlignment.Left && va == System.Windows.VerticalAlignment.Center)
            {
                double x0 = m;
                double x1 = m + width;
                double y0 = 0;
                double y1 = height;
                double y2 = (y0 + y1) / 2;
                margin = new Thickness { Left = m };
                points = new[]
                    {
                        new Point(0, y2), new Point(x0, y2 - (m / 2)), new Point(x0, y0), new Point(x1, y0),
                        new Point(x1, y1), new Point(x0, y1), new Point(x0, y2 + (m / 2))
                    };
            }

            if (ha == System.Windows.HorizontalAlignment.Right && va == System.Windows.VerticalAlignment.Center)
            {
                double x0 = 0;
                double x1 = width;
                double y0 = 0;
                double y1 = height;
                double y2 = (y0 + y1) / 2;
                margin = new Thickness { Right = m };
                points = new[]
                    {
                        new Point(x1 + m, y2), new Point(x1, y2 + (m / 2)), new Point(x1, y1), new Point(x0, y1),
                        new Point(x0, y0), new Point(x1, y0), new Point(x1, y2 - (m / 2))
                    };
            }

            if (ha == System.Windows.HorizontalAlignment.Left && va == System.Windows.VerticalAlignment.Top)
            {
                m *= 0.67;
                double x0 = m;
                double x1 = m + width;
                double y0 = m;
                double y1 = m + height;
                margin = new Thickness { Left = m, Top = m };
                points = new[]
                    {
                        new Point(0, 0), new Point(m * 2, y0), new Point(x1, y0), new Point(x1, y1), new Point(x0, y1),
                        new Point(x0, m * 2)
                    };
            }

            if (ha == System.Windows.HorizontalAlignment.Right && va == System.Windows.VerticalAlignment.Top)
            {
                m *= 0.67;
                double x0 = 0;
                double x1 = width;
                double y0 = m;
                double y1 = m + height;
                margin = new Thickness { Top = m, Right = m };
                points = new[]
                    {
                        new Point(x1 + m, 0), new Point(x1, y0 + m), new Point(x1, y1), new Point(x0, y1),
                        new Point(x0, y0), new Point(x1 - m, y0)
                    };
            }

            if (ha == System.Windows.HorizontalAlignment.Left && va == System.Windows.VerticalAlignment.Bottom)
            {
                m *= 0.67;
                double x0 = m;
                double x1 = m + width;
                double y0 = 0;
                double y1 = height;
                margin = new Thickness { Left = m, Bottom = m };
                points = new[]
                    {
                        new Point(0, y1 + m), new Point(x0, y1 - m), new Point(x0, y0), new Point(x1, y0),
                        new Point(x1, y1), new Point(x0 + m, y1)
                    };
            }

            if (ha == System.Windows.HorizontalAlignment.Right && va == System.Windows.VerticalAlignment.Bottom)
            {
                m *= 0.67;
                double x0 = 0;
                double x1 = width;
                double y0 = 0;
                double y1 = height;
                margin = new Thickness { Right = m, Bottom = m };
                points = new[]
                    {
                        new Point(x1 + m, y1 + m), new Point(x1 - m, y1), new Point(x0, y1), new Point(x0, y0),
                        new Point(x1, y0), new Point(x1, y1 - m)
                    };
            }

            if (points == null)
            {
                return null;
            }

            var pointCollection = new PointCollection();
            foreach (var point in points)
            {
                pointCollection.Add(point);
            }

            var segments = new PathSegmentCollection { new PolyLineSegment { Points = pointCollection } };
            var pf = new PathFigure { StartPoint = points[0], Segments = segments, IsClosed = true };
            return new PathGeometry { Figures = new PathFigureCollection { pf } };
        }
 //Adds a segment to the trajectory figure
 private void AddSegment(Point point)
 {
     if (this.trajectoryPathSegments == null)
     {
         this.trajectoryPathSegments = new PathSegmentCollection();
     }
     
     this.trajectoryPathSegments.Add(new LineSegment(point, true));
 }