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); }
public void Convert() { if ( m_Path.IsUnknown ) { return; } IPolylineSegment[] segments = m_Path.Segments.ToArray(); if ( segments.Length != 3 ) { return; } var startSegment = segments [ 0 ] as ITurnCircleArcSegment; var middleSegment = segments [ 1 ] as ITurnCircleArcSegment; var endSegment = segments [ 2 ] as ITurnCircleArcSegment; if ( startSegment == null || middleSegment == null || endSegment == null ) { return; } m_FiguresCollection = CreateFigures(startSegment, middleSegment, endSegment); }
public void Convert() { if ( m_Path.IsUnknown ) { return; } IPolylineSegment[] segments = m_Path.Segments.ToArray(); if ( segments.Length != 3 ) { return; } if ( IsNormalTurn(segments [ 1 ]) ) { m_FiguresCollection = ConvertTurnPath(m_Path); } else if ( IsUTurn(segments [ 1 ]) ) { m_FiguresCollection = ConvertUTurnPath(m_Path); } else { string message = "Could not determine racetrack type! - Racetrack path: {0}".Inject(m_Path); Logger.Error(message); } }
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); }
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); }
internal override PathFigureCollection GetTransformedFigureCollection(Transform transform) { // Combine the transform argument with the internal transform Transform combined = new MatrixTransform(GetCombinedMatrix(transform)); PathFigureCollection result = new PathFigureCollection(); GeometryCollection children = Children; if (children != null) { for (int i = 0; i < children.Count; i++) { PathFigureCollection pathFigures = children.Internal_GetItem(i).GetTransformedFigureCollection(combined); if (pathFigures != null) { int count = pathFigures.Count; for (int j = 0; j < count; ++j) { result.Add(pathFigures[j]); } } } } return result; }
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); }
public void MouseMove(MsaglMouseEventArgs e) { if (currentPath == null) return; var point = scroller.GetWpfPosition(e); if (DistanceBetweenWpfPoints(point, pathEnd) < 3 * currentPath.StrokeThickness) return; pathEnd = point; pathSegmentCollection.Add(new LineSegment(point, true)); var pathFigure = new PathFigure(pathStart, pathSegmentCollection, true); var pathFigureCollection = new PathFigureCollection { pathFigure }; var pathGeometry = new PathGeometry(pathFigureCollection); currentPath.Data = pathGeometry; }
public Character(char c, int line, int position) { #region set defalt properties Height = CHAR_HEIGHT; Width = (c == '\t') ? CHAR_WIDTH * 4 : CHAR_WIDTH; #endregion #region initialize children // border border = new Border(); // text text = new TextBlock(); text.FontFamily = new FontFamily("Courier New"); text.FontSize = 13; text.Foreground = new SolidColorBrush(Colors.Black); text.Text = c.ToString(); // path path = new Path(); var pg = new PathGeometry(); var pfc = new PathFigureCollection(); var pf = new PathFigure(); pf.StartPoint = new Point(0, 12); pf.Segments = new PathSegmentCollection(); pf.Segments.Add(new LineSegment() { Point = new Point(2, 14)}); pf.Segments.Add(new LineSegment() { Point = new Point(4, 12)}); pf.Segments.Add(new LineSegment() { Point = new Point(6, 14)}); pf.Segments.Add(new LineSegment() { Point = new Point(8, 12)}); pfc.Add(pf); pg.Figures = pfc; path.Data = pg; path.Stroke = new SolidColorBrush(Colors.Red); path.StrokeThickness = 0.5; path.Visibility = Visibility.Collapsed; #endregion #region add children border.Child = text; Children.Add(border); Children.Add(path); #endregion Line = line; Position = position; DoubleClickHelper.Attach(this, OnDoubleClick); }
public void ConvertAddsToFiguresTest() { var pathFigureCollection = new PathFigureCollection(); m_ConverterFigures.FiguresCollection.Returns(pathFigureCollection); m_Converter.Paths = new[] { Substitute.For <IPath>() }; m_Converter.Convert(); PathFigureCollection actual = m_Converter.Figures.First(); Assert.AreEqual(pathFigureCollection, actual); }
public void ConvertUpdatesFiguresTest() { var pathFigureCollection = new PathFigureCollection(); m_ConverterFigures.FiguresCollection.Returns(pathFigureCollection); m_Converter.Paths = new[] { Substitute.For <IPath>() }; m_Converter.Convert(); IEnumerable <PathFigureCollection> actual = m_Converter.Figures; Assert.AreEqual(1, actual.Count()); }
internal PathFigureCollection CreateFigures([NotNull] IPath path) { List <PathSegment> pathSegments = path.Segments.Select(ConvertSegment).ToList(); Point startPoint = m_Helper.PointRelativeToOrigin(path.StartPoint); var pathFigure = new PathFigure(startPoint, pathSegments, false); var figures = new PathFigureCollection { pathFigure }; return figures; }
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; }
public void Setup() { m_Logger = Substitute.For <ISelkieLogger>(); m_StartSegment = Substitute.For <ITurnCircleArcSegment>(); m_MiddleSegment = Substitute.For <ILine>(); m_EndSegment = Substitute.For <ITurnCircleArcSegment>(); m_Path = Substitute.For <IPath>(); var segments = new List <IPolylineSegment> { m_StartSegment, m_MiddleSegment, m_EndSegment }; m_Path.Segments.Returns(segments); m_UTurnPath = Substitute.For <IPath>(); var segmentsUTurn = new List <IPolylineSegment> { m_StartSegment, Substitute.For <ITurnCircleArcSegment>(), m_EndSegment }; m_UTurnPath.Segments.Returns(segmentsUTurn); m_NormalFigureCollection = new PathFigureCollection(); m_NormalConverter = Substitute.For <IRacetrackPathTurnToFiguresConverter>(); m_NormalConverter.FiguresCollection.Returns(m_NormalFigureCollection); m_UTurnFigureCollection = new PathFigureCollection(); m_UTurnConverter = Substitute.For <IRacetrackPathUTurnToFiguresConverter>(); m_UTurnConverter.FiguresCollection.Returns(m_UTurnFigureCollection); m_Converter = new RacetrackPathToFiguresConverter(m_NormalConverter, m_UTurnConverter) { Logger = m_Logger }; }
Path GetArcPath(double startPosX, double startPosY, double endPosX, double endPosY, int width, int height) { var pthFigure = new PathFigure(); var arcSeg = new ArcSegment(); if (startPosX == endPosX && startPosY == startPosY) { pthFigure.StartPoint = new Point(startPosX - SelfLoopArcDx, startPosY - SelfLoopArcDy); arcSeg.Point = new Point(endPosX + SelfLoopArcDx, endPosY - SelfLoopArcDy); } else { pthFigure.StartPoint = new Point(startPosX, startPosY); arcSeg.Point = new Point(endPosX, endPosY); } arcSeg.Size = new Size(width, height); arcSeg.IsLargeArc = true; arcSeg.RotationAngle = DefaultArcAngle; var myPathSegmentCollection = new PathSegmentCollection { arcSeg }; pthFigure.Segments = myPathSegmentCollection; var pthFigureCollection = new PathFigureCollection { pthFigure }; var pthGeometry = new PathGeometry { Figures = pthFigureCollection }; var arcPath = new Path { Stroke = new SolidColorBrush(Colors.Black), StrokeThickness = DefaultThickness, Data = pthGeometry }; return(arcPath); }
private static Geometry AddSubFolder(PathFigureCollection pFc, PathGeometry pG) { // front bigger AddLine(new Point(0, 10), new Point(0, 70), pFc); AddLine(new Point(0, 70), new Point(25, 75), pFc); AddLine(new Point(25, 75), new Point(30, 70), pFc); AddLine(new Point(30, 70), new Point(30, 25), pFc); AddLine(new Point(30, 25), new Point(10, 10), pFc); // back bigger AddLine(new Point(0, 10), new Point(40, 10), pFc); AddLine(new Point(40, 10), new Point(45, 15), pFc); AddLine(new Point(45, 15), new Point(45, 35), pFc); // front smaller AddLine(new Point(25, 75), new Point(25, 85), pFc); AddLine(new Point(25, 85), new Point(50, 90), pFc); AddLine(new Point(50, 90), new Point(50, 45), pFc); AddLine(new Point(50, 45), new Point(30, 40), pFc); // back smaller AddLine(new Point(30, 35), new Point(55, 35), pFc); AddLine(new Point(55, 35), new Point(60, 40), pFc); AddLine(new Point(60, 40), new Point(60, 50), pFc); AddLine(new Point(60, 65), new Point(60, 80), pFc); AddLine(new Point(60, 80), new Point(50, 80), pFc); // arrow AddLine(new Point(55, 50), new Point(85, 50), pFc); AddLine(new Point(85, 50), new Point(85, 40), pFc); AddLine(new Point(85, 40), new Point(100, 57.5f), pFc); AddLine(new Point(100, 57.5f), new Point(85, 75), pFc); AddLine(new Point(85, 75), new Point(85, 65), pFc); AddLine(new Point(85, 65), new Point(55, 65), pFc); AddLine(new Point(55, 65), new Point(55, 50), pFc); pG.Figures = pFc; return(pG); }
private static System.Windows.Shapes.Path GetRandomPath(int maxWidth, int maxHeight) { var pathFigure = new PathFigure { StartPoint = new Point(Random.Next(0, maxWidth / 10), Random.Next(0, maxHeight)) }; var pointCollection = new PointCollection(9) { new Point(Random.Next(maxWidth / 10, maxWidth * 2 / 10), Random.Next(0, maxHeight)), new Point(Random.Next(maxWidth * 2 / 10, maxWidth * 3 / 10), Random.Next(0, maxHeight)), new Point(Random.Next(maxWidth * 3 / 10, maxWidth * 4 / 10), Random.Next(0, maxHeight)), new Point(Random.Next(maxWidth * 4 / 10, maxWidth * 5 / 10), Random.Next(0, maxHeight)), new Point(Random.Next(maxWidth * 5 / 10, maxWidth * 6 / 10), Random.Next(0, maxHeight)), new Point(Random.Next(maxWidth * 6 / 10, maxWidth * 7 / 10), Random.Next(0, maxHeight)), new Point(Random.Next(maxWidth * 7 / 10, maxWidth * 8 / 10), Random.Next(0, maxHeight)), new Point(Random.Next(maxWidth * 8 / 10, maxWidth * 9 / 10), Random.Next(0, maxHeight)), new Point(Random.Next(maxWidth * 9 / 10, maxWidth), Random.Next(0, maxHeight)) }; var bezierSegment = new PolyBezierSegment { Points = pointCollection }; var pathSegmentCollection = new PathSegmentCollection { bezierSegment }; pathFigure.Segments = pathSegmentCollection; var pathFigureCollection = new PathFigureCollection { pathFigure }; var pathGeometry = new PathGeometry { Figures = pathFigureCollection }; var path = new System.Windows.Shapes.Path { Stroke = Brushes.Black, StrokeThickness = 1, Data = pathGeometry }; return(path); }
/// <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 override void Draw(Canvas canvas, double scaleFactor) { PointMassA.Draw(canvas, scaleFactor); PointMassB.Draw(canvas, scaleFactor); var x1 = PointMassA.XPos * scaleFactor; var y1 = PointMassA.YPos * scaleFactor; var startPoint = new System.Windows.Point(x1, y1); var pathFigure = new PathFigure { StartPoint = startPoint }; var x2 = PointMassB.XPos * scaleFactor; var y2 = PointMassB.YPos * scaleFactor; var point = new System.Windows.Point(x2, y2); var lineSegment1A = new LineSegment { Point = point }; pathFigure.Segments.Add(lineSegment1A); var pathFigureCollection = new PathFigureCollection { pathFigure }; var pathGeometry = new PathGeometry { Figures = pathFigureCollection }; var path = new Path { Stroke = Brushes.Black, StrokeThickness = 3.0, Data = pathGeometry, // RenderTransform = translateTransform }; canvas.Children.Add(path); }
private void SetProperties(Path line) { var myLineSegment = new LineSegment() { Point = new System.Windows.Point(this.Element.Width, 0) }; var myPathSegmentCollection = new PathSegmentCollection(); myPathSegmentCollection.Add(myLineSegment); var myPathFigureCollection = new PathFigureCollection(); myPathFigureCollection.Add(new PathFigure() { StartPoint = new System.Windows.Point(0, 0), Segments = myPathSegmentCollection }); line.Stroke = this.Element.Color.ToBrush(); line.StrokeDashArray = new System.Windows.Media.DoubleCollection(); if (this.Element.StrokeType != StrokeType.Solid) { if (this.Element.StrokeType == StrokeType.Dashed) { line.StrokeDashArray.Add(10); } line.StrokeDashArray.Add(2); } line.Data = new PathGeometry() { Figures = myPathFigureCollection }; line.StrokeThickness = this.Element.Thickness; }
private void CreateGeometry() { Point[] bezierPoints = { start, control1, control2, end }; //Generate bezier points var b = GetBezierApproximation(bezierPoints, 256); //Calcule TopPosition CalculateTopCurvePoint(b); PathFigure pf = new PathFigure(b.Points[0], new[] { b }, false); PathFigureCollection pfc = new PathFigureCollection(); pfc.Add(pf); var pge = new PathGeometry(); pge.Figures = pfc; bezierCurve = new PathGeometry(); bezierCurve = pge; }
public void EndCollect() { if (this.PathGenerated != null && _psCollection.Count > 0) { PathGeometry pg = new PathGeometry(); pg.FillRule = FillRule.Nonzero; PathFigureCollection figs = new PathFigureCollection(); pg.Figures = figs; //닫힌 Path를 형성함 PathSegmentCollection pscol2 = _psCollection.Clone(); PathSegment last = pscol2.Last(); pscol2.Insert(0, last); PathFigure fig = new PathFigure(); fig.Segments = pscol2; fig.IsClosed = true; figs.Add(fig); this.PathGenerated(pg); } }
/// <summary> /// 根据所有的点,组成一个封闭区域,且可以填充,并且填充 /// </summary> /// <param name="points"></param> /// <param name="brush"></param> protected virtual void DrawFill(List <Vector2D> points) { DrawingContext dc = this.RenderOpen(); Pen.Freeze(); //冻结画笔,这样能加快绘图速度 PathGeometry paths = new PathGeometry(); PathFigureCollection pfc = new PathFigureCollection(); PathFigure pf = new PathFigure(); pfc.Add(pf); pf.StartPoint = KernelProperty.MMToPix(points[0]); for (int i = 0; i < points.Count; i++) { LineSegment ps = new LineSegment(); ps.Point = KernelProperty.MMToPix(points[i]); pf.Segments.Add(ps); } pf.IsClosed = true; paths.Figures = pfc; dc.DrawGeometry(Brush, Pen, paths); dc.Close(); }
//***************************************************************************** ///</summary> ///绘制线段但是不是在画布上实现这个 ///</summary> //TODO:把Drawing画在画布上 protected void Drawing() { 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; // Add path shape to the UI. StackPanel mainPanel = new StackPanel(); mainPanel.Children.Add(myPath); this.Content = mainPanel; }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { double def = 132.5; object x = values[0]; double chevAngle = def; if (x is double) { chevAngle = (double)values[0]; } double width = values[1] is double?(double)values[1] : 0; double height = values[2] is double?(double)values[2] : 0; double angleFromCenter = (180.0 - chevAngle) / 2; double thirdAngle = 180.0 - 90.0 - angleFromCenter; double halfHeight = height / 2.0; double A = (Math.PI * thirdAngle) / 180.0; double B = (Math.PI * 90.0) / 180.0; double C = (Math.PI * angleFromCenter) / 180.0; double a = halfHeight; double b = (a * Math.Sin(B)) / Math.Sin(A); double c = (a * (Math.Sin(C))) / Math.Sin(A); var z = new PathFigureCollection(); var fig = new PathFigure(); fig.IsClosed = true; fig.StartPoint = new Point(0, 0); fig.Segments.Add(new LineSegment(new Point(0, height), false)); fig.Segments.Add(new LineSegment(new Point(c, halfHeight), false)); //fig.Segments.Add(new LineSegment(new Point(0,0), false)); z.Add(fig); return(z); }
private void assembleGeo() { if (Model == null) { return; } if (Model.PointList == null) { return; } if (Model.PointList.Count == 0 || Line.isSubstituteLine) { return; } PathGeometry geo = new PathGeometry(); PathFigure myPathFigure = new PathFigure(); PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); PathFigureCollection myPathFigureCollection = new PathFigureCollection(); myPathFigure.StartPoint = Line.PointList[0].From; foreach (var fromto in Line.PointList) { LineSegment myLineSegment = new LineSegment(); myLineSegment.Point = fromto.To; myPathSegmentCollection.Add(myLineSegment); } myPathFigure.Segments = myPathSegmentCollection; myPathFigureCollection.Add(myPathFigure); geo.Figures = myPathFigureCollection; PathGeo = geo; }
private Path ArcSegmentLine() { // <Snippet36> PathFigure myPathFigure = new PathFigure(); myPathFigure.StartPoint = new Point(10, 100); ArcSegment myArcSegment = new ArcSegment(); myArcSegment.Size = new Size(100, 50); myArcSegment.RotationAngle = 45; myArcSegment.IsLargeArc = true; myArcSegment.SweepDirection = SweepDirection.Counterclockwise; myArcSegment.Point = new Point(200, 100); PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); myPathSegmentCollection.Add(myArcSegment); 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; // </Snippet36> return(myPath); }
private Path TwoLineSegments() { // <Snippet49> PathFigure myPathFigure = new PathFigure(); myPathFigure.StartPoint = new Point(10, 100); myPathFigure.IsClosed = true; LineSegment myLineSegment1 = new LineSegment(); myLineSegment1.Point = new Point(100, 100); LineSegment myLineSegment2 = new LineSegment(); myLineSegment2.Point = new Point(100, 50); PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); myPathSegmentCollection.Add(myLineSegment1); myPathSegmentCollection.Add(myLineSegment2); 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; // </Snippet49> return(myPath); }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { base.DrawCore(drawingContext, drawingAttributes); UpdateShapePoints(); LineSegment topRightSeg = new LineSegment(topRight, true); LineSegment rightSeg = new LineSegment(right, true); LineSegment bottomRightSeg = new LineSegment(bottomRight, true); LineSegment leftSeg = new LineSegment(left, true); LineSegment bottomLeftSeg = new LineSegment(bottomLeft, true); PathSegmentCollection segments = new PathSegmentCollection { topRightSeg, rightSeg, bottomRightSeg, bottomLeftSeg, leftSeg }; PathFigure figure = new PathFigure(); figure.Segments = segments; figure.IsClosed = true; figure.StartPoint = topLeft; PathFigureCollection figures = new PathFigureCollection { figure }; PathGeometry geometry = new PathGeometry(); geometry.Figures = figures; drawingContext.DrawGeometry(fillColor, pen, geometry); FormattedText formattedText = new FormattedText(name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); formattedText.MaxTextWidth = shapeStyle.width; formattedText.TextAlignment = TextAlignment.Center; formattedText.MaxTextHeight = 100; drawingContext.DrawText(formattedText, GetCustomBound().BottomLeft); }
private void menuLines_Click(object sender, RoutedEventArgs e) { Line line = new Line(); line.Stroke = Brushes.ForestGreen; line.StrokeThickness = 8; line.X1 = 0; line.X2 = canvas.ActualWidth; line.Y1 = canvas.ActualHeight / 2; line.Y2 = canvas.ActualHeight / 2; canvas.Children.Add(line); Path curvedLine = new Path(); curvedLine.Stroke = Brushes.DeepSkyBlue; curvedLine.StrokeThickness = 2; PathGeometry myGeometry = new PathGeometry(); PathFigureCollection figureCollection = new PathFigureCollection(); PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = new Point(10, 100); PathSegmentCollection psc = new PathSegmentCollection(); BezierSegment bs = new BezierSegment(); bs.Point1 = new Point(100, 0); bs.Point2 = new Point(200, 200); bs.Point3 = new Point(300, 100); psc.Add(bs); pathFigure.Segments = psc; figureCollection.Add(pathFigure); myGeometry.Figures = figureCollection; curvedLine.Data = myGeometry; canvas.Children.Add(curvedLine); }
private Path DrawSlice(int slice, int count) { double gap = Properties.Settings.Default.Gap; double innerFraction = Properties.Settings.Default.InnerFraction; double halfSliceSweep = Math.PI / count; double bisector = Math.PI * ((double)slice / count * 2.0 - 0.5); double angleOffsetOuter = halfSliceSweep - gap; double angleOffsetInner = halfSliceSweep - gap / innerFraction; double outerRadius = content.Width / 2.0; double innerRadius = outerRadius * innerFraction; Point startOuter = PointOnCircle(bisector - angleOffsetOuter, outerRadius); Point startInner = PointOnCircle(bisector - angleOffsetInner, innerRadius); Point endOuter = PointOnCircle(bisector + angleOffsetOuter, outerRadius); Point endInner = PointOnCircle(bisector + angleOffsetInner, innerRadius); var sizeOuter = new Size(outerRadius, outerRadius); var sizeInner = new Size(innerRadius, innerRadius); var segments = new PathSegmentCollection(); segments.Add(new ArcSegment(endOuter, sizeOuter, 45.0, isLargeArc: false, SweepDirection.Clockwise, isStroked: false)); segments.Add(new LineSegment(endInner, isStroked: false)); segments.Add(new ArcSegment(startInner, sizeInner, 45.0, isLargeArc: false, SweepDirection.Counterclockwise, isStroked: false)); segments.Add(new LineSegment(startOuter, isStroked: false)); var figure = new PathFigure(startOuter, segments, true); var figures = new PathFigureCollection(); figures.Add(figure); var path = new Path(); var geo = new PathGeometry(figures); path.Data = geo; path.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 0)); return(path); }
private void VerticalSetup() { PathFigure fig = new PathFigure { StartPoint = new System.Windows.Point(0, 0) }; LineSegment seg1 = new LineSegment { Point = new System.Windows.Point(0, this.Height) }; LineSegment seg2 = new LineSegment { Point = new System.Windows.Point(this.Height, this.Height / 2) }; PathSegmentCollection collect = new PathSegmentCollection(); collect.Add(seg1); collect.Add(seg2); fig.Segments = collect; PathFigureCollection pathFig = new PathFigureCollection(); pathFig.Add(fig); this.path.Figures = pathFig; this.trace.Y1 = this.Height / 2; this.trace.Y2 = this.Height / 2; this.trace.X1 = this.TraceLength; this.trace.X2 = this.Height; }
private static Geometry Movie(PathFigureCollection pFc, PathGeometry pG) { var d = 20d; AddLine(new Point(0, 0), new Point(0, 100), pFc); AddLine(new Point(d, 0), new Point(d, 100), pFc); AddLine(new Point(100, 0), new Point(100, 100), pFc); AddLine(new Point(100 - d, 0), new Point(100 - d, 100), pFc); for (int i = 0; i < 6; i++) { AddHLine(new Point(0, i * d), d, pFc); AddHLine(new Point(100, i * d), -d, pFc); } AddHLine(new Point(d, 0), 100 - d * 2, pFc); AddHLine(new Point(d, 50), 100 - d * 2, pFc); AddHLine(new Point(d, 100), 100 - d * 2, pFc); pG.Figures = pFc; return(pG); }
private static void Figures_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) { //todo: find a way to know when the points changed in the collection PathGeometry geometry = (PathGeometry)d; PathFigureCollection oldCollection = (PathFigureCollection)e.OldValue; PathFigureCollection newCollection = (PathFigureCollection)e.NewValue; if (oldCollection != newCollection) { if (oldCollection != null) { oldCollection.SetParentPath(null); } if (geometry.INTERNAL_parentPath != null && geometry.INTERNAL_parentPath._isLoaded) { if (newCollection != null) { newCollection.SetParentPath(geometry.INTERNAL_parentPath); } geometry.INTERNAL_parentPath.ScheduleRedraw(); } } }
private static PathGeometry ExitGeo(PathFigureCollection pFc, PathGeometry pG) { //AddLine(new Point(0, 0), new Point(100, 100), pFc); //AddLine(new Point(100, 0), new Point(0, 100), pFc); AddLine(new Point(10, 0), new Point(50, 40), pFc); AddLine(new Point(10, 0), new Point(0, 10), pFc); AddLine(new Point(0, 10), new Point(40, 50), pFc); AddLine(new Point(90, 0), new Point(50, 40), pFc); AddLine(new Point(90, 0), new Point(100, 10), pFc); AddLine(new Point(100, 10), new Point(60, 50), pFc); AddLine(new Point(10, 100), new Point(50, 60), pFc); AddLine(new Point(10, 100), new Point(0, 90), pFc); AddLine(new Point(0, 90), new Point(40, 50), pFc); AddLine(new Point(90, 100), new Point(50, 60), pFc); AddLine(new Point(90, 100), new Point(100, 90), pFc); AddLine(new Point(100, 90), new Point(60, 50), pFc); pG.Figures = pFc; return(pG); }
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; }
public Path WpfPolyline(wCurve Shp, wGraphic Graphics, wEffects ShapeEffects) { Path X = new Path(); wPolyline C = (wPolyline)Shp; PathFigure Pf = new PathFigure(); PolyLineSegment S = new PolyLineSegment(); PathGeometry G = new PathGeometry(); PathFigureCollection Fc = new PathFigureCollection(); PathSegmentCollection Sc = new PathSegmentCollection(); Pf.StartPoint = new System.Windows.Point(C.Points[0].X * Scale, C.Points[0].Y * Scale); for (int i = 1; i < C.Points.Count; i++) { wPoint P = C.Points[i]; S.Points.Add(new System.Windows.Point(P.X * Scale, P.Y * Scale)); } Sc.Add(S); Pf.Segments = Sc; Fc.Add(Pf); G.Figures = Fc; X.Data = G; X.StrokeMiterLimit = 1.0; X.RenderTransform = Xform; X = SetPathFill(X, Graphics); X = SetPathStroke(X, Graphics); X = SetPathEffects(X, ShapeEffects); group.Shapes.Add(new wShape(G, Graphics)); return(X); }
/// <summary> /// Return a clip geometry for the specified point in the List of Tuples /// and the next point, for a single sextant of the hexagon using the sextant's /// local bounding box upper-left corner as the 0,0 coordinate location /// </summary> /// <param name="verticies"></param> /// <param name="startingPoint"></param> /// <returns></returns> public static Geometry AsSextantClipGeometry(this List <Tuple <double, double> > verticies, int startingPoint) { var centerPoint = new Point(verticies.Average(v => v.Item1), verticies.Average(v => v.Item2)); var vertex1 = verticies[startingPoint].AsPoint(); var vertex2 = startingPoint == 5 ? verticies[0].AsPoint() : verticies[startingPoint + 1].AsPoint(); // Adjust everything to a coordinate system where the upper left // bound of this sextant is 0,0 var deltaX = Math.Min(centerPoint.X, Math.Min(vertex1.X, vertex2.X)); var deltaY = Math.Min(centerPoint.Y, Math.Min(vertex1.Y, vertex2.Y)); centerPoint.X -= deltaX; vertex1.X -= deltaX; vertex2.X -= deltaX; centerPoint.Y -= deltaY; vertex1.Y -= deltaY; vertex2.Y -= deltaY; var segmentCollection = new PathSegmentCollection(2) { new LineSegment(vertex1, true), new LineSegment(vertex2, true) }; var figureCollection = new PathFigureCollection(1) { new PathFigure(centerPoint, segmentCollection, true) }; var clip = new PathGeometry(figureCollection) { FillRule = FillRule.Nonzero }; return(clip); }
private void DrawArcSegment(Point start, Point end, SweepDirection dir) { // DebugUtil.Log("draw arc: " + start.X + " " + start.Y + " " + end.X + " " + end.Y + " " + dir); PathFigure pthFigure = new PathFigure(); pthFigure.StartPoint = start; ArcSegment arcSeg = new ArcSegment(); arcSeg.Point = end; arcSeg.Size = new Size(Math.Abs(start.X - end.X), Math.Abs(start.Y - end.Y)); arcSeg.IsLargeArc = false; arcSeg.SweepDirection = dir; arcSeg.RotationAngle = 90; PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); myPathSegmentCollection.Add(arcSeg); pthFigure.Segments = myPathSegmentCollection; PathFigureCollection pthFigureCollection = new PathFigureCollection(); pthFigureCollection.Add(pthFigure); PathGeometry pthGeometry = new PathGeometry(); pthGeometry.Figures = pthFigureCollection; Windows.UI.Xaml.Shapes.Path arcPath = new Windows.UI.Xaml.Shapes.Path(); arcPath.Stroke = this.Stroke; arcPath.StrokeThickness = this.StrokeThickness; arcPath.Data = pthGeometry; Lines.Children.Add(arcPath); }
public static Path SetStarForSinglePoint(Point p, Brush brush, Canvas canvas) { PathFigureCollection myPathFigureCollection = new PathFigureCollection(); double cornerDist = OptionDrawLine.oneDotCornerDistance; double middleDist = OptionDrawLine.oneDotMiddleDistance; Vector[] vect = new Vector[6]; vect[0] = new Vector(cornerDist, cornerDist); vect[1] = new Vector(-cornerDist, cornerDist); vect[2] = new Vector(cornerDist, -cornerDist); vect[3] = new Vector(-cornerDist, -cornerDist); vect[4] = new Vector(-middleDist, 0); vect[5] = new Vector(middleDist, 0); for (int i = 0; i < 6; i++) { PathFigure myPathFigure = new PathFigure(); myPathFigure.StartPoint = p; PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); LineSegment myLineSegment = new LineSegment(); myLineSegment.Point = new Point(p.X + vect[i].X, p.Y + vect[i].Y); myPathSegmentCollection.Add(myLineSegment); myPathFigure.Segments = myPathSegmentCollection; myPathFigureCollection.Add(myPathFigure); } PathGeometry myPathGeometry = new PathGeometry(); myPathGeometry.Figures = myPathFigureCollection; Path myPath = new Path(); myPath.Stroke = brush; myPath.StrokeThickness = OptionDrawLine.strokeThickness; myPath.Data = myPathGeometry; canvas.Children.Add(myPath); return(myPath); }
public static Geometry CreateTriangleGeometry(Point p1, Point p2, Point p3) { PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = p1; PathSegmentCollection segments1 = pathFigure.Segments; LineSegment lineSegment1 = new LineSegment(); Point point1 = p2; lineSegment1.Point = point1; ((PresentationFrameworkCollection <PathSegment>)segments1).Add((PathSegment)lineSegment1); PathSegmentCollection segments2 = pathFigure.Segments; LineSegment lineSegment2 = new LineSegment(); Point point2 = p3; lineSegment2.Point = point2; ((PresentationFrameworkCollection <PathSegment>)segments2).Add((PathSegment)lineSegment2); PathGeometry pathGeometry = new PathGeometry(); PathFigureCollection figureCollection = new PathFigureCollection(); pathGeometry.Figures = figureCollection; ((PresentationFrameworkCollection <PathFigure>)pathGeometry.Figures).Add(pathFigure); return((Geometry)pathGeometry); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { PointCollection points = (PointCollection)value; if (targetType != typeof(PointCollection)) { //throw new InvalidOperationException("The target must be a boolean"); } if (parameter != null && points.Count > 0) { PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = points[0]; //List<LineSegment> segments = new List<LineSegment>(); PathSegmentCollection pathSegmentCollection = new PathSegmentCollection(); for (int i = 0; i < points.Count; i++) { LineSegment lineSegment = new LineSegment(); //segments.Add(lineSegment); lineSegment.Point = points[i]; pathSegmentCollection.Add(lineSegment); } pathFigure.Segments = pathSegmentCollection; PathFigureCollection pathFigureCollection = new PathFigureCollection(); pathFigureCollection.Add(pathFigure); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures = pathFigureCollection; return(pathGeometry); } else { return(null); } }
private static Geometry Remove(PathFigureCollection pFc, PathGeometry pG) { AddLine(pFc, new Point(20, 0), new Point(60, 0), new Point(60, 70), new Point(0, 70), new Point(0, 20), new Point(20, 0)); AddLine(pFc, new Point(20, 0), new Point(20, 20), new Point(0, 20)); // a couple text lines representing content AddHLine(new Point(10, 20), 40, pFc); AddHLine(new Point(10, 35), 40, pFc); AddHLine(new Point(10, 50), 40, pFc); AddLine(new Point(35, 35), new Point(100, 100), pFc); AddLine(new Point(100, 35), new Point(35, 100), pFc); pG.Figures = pFc; return(pG); }
private void HorizontalSetup() { PathFigure arrowStart = new PathFigure { StartPoint = new System.Windows.Point(0, 0) }; LineSegment arrowRight = new LineSegment { Point = new System.Windows.Point(this.Height, 0) }; LineSegment arrowBottom = new LineSegment { Point = new System.Windows.Point(this.Height / 2, this.Height) }; PathSegmentCollection arrow = new PathSegmentCollection(); arrow.Add(arrowRight); arrow.Add(arrowBottom); arrowStart.Segments = arrow; PathFigureCollection pathFig = new PathFigureCollection(); pathFig.Add(arrowStart); this.path.Figures = pathFig; this.trace.X1 = this.Height / 2; this.trace.X2 = this.Height / 2; this.trace.Y1 = this.TraceLength; this.trace.Y2 = this.Height; }
public void MouseMove(MsaglMouseEventArgs e) { if (currentPath == null) { return; } var point = scroller.GetWpfPosition(e); if (DistanceBetweenWpfPoints(point, pathEnd) < 3 * currentPath.StrokeThickness) { return; } pathEnd = point; pathSegmentCollection.Add(new LineSegment(point, true)); var pathFigure = new PathFigure(pathStart, pathSegmentCollection, true); var pathFigureCollection = new PathFigureCollection { pathFigure }; var pathGeometry = new PathGeometry(pathFigureCollection); currentPath.Data = pathGeometry; }
/// <summary> /// 刷新当前图形元素 /// </summary> public override void Update() { DrawingContext dc = this.RenderOpen(); Pen.Freeze(); //冻结画笔,这样能加快绘图速度 this.DashStyle = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10); this.PenColor = Colors.DeepSkyBlue; this.Pen.EndLineCap = PenLineCap.Triangle; ArcSegment arc = new ArcSegment(); arc.IsLargeArc = true; if (start.AngleFrom(end) >= Math.PI) { arc.IsLargeArc = false; } else { arc.IsLargeArc = true; } arc.RotationAngle = 0; arc.Size = new System.Windows.Size(100, 100); arc.Point = KernelProperty.MMToPix(this.end); PathGeometry paths = new PathGeometry(); paths.FillRule = FillRule.EvenOdd; PathFigureCollection pfc = new PathFigureCollection(); PathFigure pf = new PathFigure(); pfc.Add(pf); pf.StartPoint = KernelProperty.MMToPix(this.start); pf.Segments.Add(arc); paths.Figures = pfc; dc.DrawGeometry(Brush, Pen, paths); SeText(dc, Line2D.Create(start, end)); dc.Close(); }
internal override PathFigureCollection GetTransformedFigureCollection(Transform transform) { Point [] points = GetPointList(); // Get the combined transform argument with the internal transform Matrix matrix = GetCombinedMatrix(transform); if (!matrix.IsIdentity) { for (int i=0; i<points.Length; i++) { points[i] *= matrix; } } PathFigureCollection figureCollection = new PathFigureCollection(); figureCollection.Add( new PathFigure( points[0], new PathSegment[]{ new BezierSegment(points[1], points[2], points[3], true, true), new BezierSegment(points[4], points[5], points[6], true, true), new BezierSegment(points[7], points[8], points[9], true, true), new BezierSegment(points[10], points[11], points[12], true, true)}, true ) ); return figureCollection; }
// Call every frame refresh public void RefreshTrajectory(Skeleton skeleton, Point center, int trackedSkeleton) { this.currentSkeleton = skeleton; this.trackedSkeleton = trackedSkeleton; this.currentPoint = center; this.AddPoint(currentPoint); switch (trackedSkeleton) { case 1: this.TrajectoryBrush = Brushes.White; break; case 2: this.TrajectoryBrush = Brushes.Salmon; break; case 3: this.TrajectoryBrush = Brushes.YellowGreen; break; case 4: this.TrajectoryBrush = Brushes.Orange; break; case 5: this.TrajectoryBrush = Brushes.Purple; break; case 6: this.TrajectoryBrush = Brushes.Yellow; break; default: this.TrajectoryBrush = Brushes.Pink; break; } //Draw the trajectory if (shouldDraw) { this.trajectoryPathFigure = new PathFigure(pointList.First(), trajectoryPathSegments, false); this.trajectoryPathFigureCollection = new PathFigureCollection(); this.trajectoryPathFigureCollection.Add(trajectoryPathFigure); this.trajectoryPathGeometry = new PathGeometry(trajectoryPathFigureCollection); } //At first point add trajectory row to dataset if (pointList.Count == 1) { addTrajectory(); } //if only one point do not calculate the distance if (pointList.Count > 0) { IncrementDistance(currentSkeleton.Position); } this.InvalidateVisual(); }
// 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(); }
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 void EndPoint() { var pathfig = new PathFigure(); pathfig.StartPoint = this.start.Value; pathfig.Segments = this.segments; var pathfigcoll = new PathFigureCollection(); pathfigcoll.Add(pathfig); var pathgeo = new PathGeometry(); pathgeo.Figures = pathfigcoll; this.path.Data = pathgeo; }
public LineGraph() { if(Settings == null) Settings = new LineGraphSettings(); filters.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(filters_CollectionChanged); path = new Path(); geom = new PathGeometry(); figures = new PathFigureCollection(); figure = new PathFigure(); segments = new PathSegmentCollection(); figure.Segments = segments; figures.Add(figure); geom.Figures = figures; path.Data = geom; path.StrokeLineJoin = PenLineJoin.Round; path.StrokeThickness = settings.LineThickness; path.SetBinding(Path.StrokeProperty, new System.Windows.Data.Binding() { Source = this, Path = new PropertyPath("LineColor") }); Filters.Add(new Microsoft.Research.DynamicDataDisplay.Filters.FrequencyFilter()); }
public object Convert( object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture ) { Debug.Assert( values != null && values.Length == 9, "EdgeRouteToPathConverter should have 9 parameters: pos (1,2), size (3,4) of source; pos (5,6), size (7,8) of target; routeInformation (9)." ); #region Get the inputs //get the position of the source Point sourcePos = new Point() { X = ( values[0] != DependencyProperty.UnsetValue ? (double)values[0] : 0.0 ), Y = ( values[1] != DependencyProperty.UnsetValue ? (double)values[1] : 0.0 ) }; //get the size of the source Size sourceSize = new Size() { Width = ( values[2] != DependencyProperty.UnsetValue ? (double)values[2] : 0.0 ), Height = ( values[3] != DependencyProperty.UnsetValue ? (double)values[3] : 0.0 ) }; //get the position of the target Point targetPos = new Point() { X = ( values[4] != DependencyProperty.UnsetValue ? (double)values[4] : 0.0 ), Y = ( values[5] != DependencyProperty.UnsetValue ? (double)values[5] : 0.0 ) }; //get the size of the target Size targetSize = new Size() { Width = ( values[6] != DependencyProperty.UnsetValue ? (double)values[6] : 0.0 ), Height = ( values[7] != DependencyProperty.UnsetValue ? (double)values[7] : 0.0 ) }; //get the route informations Point[] routeInformation = ( values[8] != DependencyProperty.UnsetValue ? (Point[])values[8] : null ); #endregion bool hasRouteInfo = routeInformation != null && routeInformation.Length > 0; // // Create the path // Point p1 = GraphConverterHelper.CalculateAttachPoint( sourcePos, sourceSize, ( hasRouteInfo ? routeInformation[0] : targetPos ) ); Point p2 = GraphConverterHelper.CalculateAttachPoint( targetPos, targetSize, ( hasRouteInfo ? routeInformation[routeInformation.Length - 1] : sourcePos ) ); PathSegment[] segments = new PathSegment[1 + ( hasRouteInfo ? routeInformation.Length : 0 )]; if ( hasRouteInfo ) //append route points for ( int i = 0; i < routeInformation.Length; i++ ) segments[i] = new LineSegment( routeInformation[i], true ); Point pLast = ( hasRouteInfo ? routeInformation[routeInformation.Length - 1] : p1 ); Vector v = pLast - p2; v = v / v.Length * 5; Vector n = new Vector( -v.Y, v.X ) * 0.3; segments[segments.Length - 1] = new LineSegment( p2 + v, true ); PathFigureCollection pfc = new PathFigureCollection( 2 ); pfc.Add( new PathFigure( p1, segments, false ) ); pfc.Add( new PathFigure( p2, new PathSegment[] { new LineSegment(p2 + v - n, true), new LineSegment(p2 + v + n, true)}, true ) ); return pfc; }
private Path StrokeToPath(Stroke oStroke) { PathFigure myPathFigure = null; LineSegment myLineSegment = null; PathFigureCollection myPathFigureCollection = new PathFigureCollection(); PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); if (oStroke == null) return null; // Number of points. int n = oStroke.StylusPoints.Count; if (n == 0) return null; // Start point is first point from sytluspoints collection (M, item 0). myPathFigure = new PathFigure(); myPathFigure.StartPoint = new Point(oStroke.StylusPoints[0].X, oStroke.StylusPoints[0].Y); myPathFigureCollection.Add(myPathFigure); // Make small line segment L if there is only one point in the Stroke (workaround). // Data with only M is not shown. if (n == 1) { myLineSegment = new LineSegment(); myLineSegment.Point = new Point(oStroke.StylusPoints[0].X + 1, oStroke.StylusPoints[0].Y + 1); myPathSegmentCollection.Add(myLineSegment); } // The other points are line segments (L, items 1..n-1). for (int i = 1; i < n; i++) { myLineSegment = new LineSegment(); myLineSegment.Point = new Point(oStroke.StylusPoints[i].X, oStroke.StylusPoints[i].Y); myPathSegmentCollection.Add(myLineSegment); } myPathFigure.Segments = myPathSegmentCollection; PathGeometry myPathGeometry = new PathGeometry(); myPathGeometry.Figures = myPathFigureCollection; Path oPath = new Path(); // Add the data to the Path. oPath.Data = myPathGeometry; // <-| // Copy Stroke properties to Path. // ---------------------------------------- // Stroke color. Color oC = oStroke.DrawingAttributes.Color; // Stroke color. SolidColorBrush oBr = new SolidColorBrush(); oBr.Color = oC; oPath.Stroke = oBr; // Stroke thickness. double dW = oStroke.DrawingAttributes.Width; // Width of stylus. double dH = oStroke.DrawingAttributes.Height; // Height of stylus. oPath.StrokeThickness = dW; // Attribute FitToCurve. // FitToCurve has no effect on the points, oStroke.StylusPoints is used. // See also oStroke.GetBezierStylusPoints(). // See also test with GetAllPoints(). // Stroke has no Fill property in attributes. // oPath.Fill = mySolidColorBrush; // ---------------------------------------- return oPath; }
private static PathGeometry CreateGeometry(Size contentDesiredSize) { //TODO Make better :) do some funky beziers or summit const double cheapRadiusBig = 6.0; const double cheapRadiusSmall = cheapRadiusBig/2; const int angle = 20; const double radians = angle * (Math.PI / 180); var startPoint = new Point(0, contentDesiredSize.Height + cheapRadiusSmall + cheapRadiusSmall); //clockwise starting at bottom left var bottomLeftSegment = new ArcSegment(new Point(startPoint.X + cheapRadiusSmall, startPoint.Y - cheapRadiusSmall), new Size(cheapRadiusSmall, cheapRadiusSmall), 315, false, SweepDirection.Counterclockwise, true); var triangleX = Math.Tan(radians) * (contentDesiredSize.Height); var leftSegment = new LineSegment(new Point(bottomLeftSegment.Point.X + triangleX, bottomLeftSegment.Point.Y - contentDesiredSize.Height), true); var topLeftSegment = new ArcSegment(new Point(leftSegment.Point.X + cheapRadiusBig, leftSegment.Point.Y - cheapRadiusSmall), new Size(cheapRadiusBig, cheapRadiusBig), 120, false, SweepDirection.Clockwise, true); var topSegment = new LineSegment(new Point(contentDesiredSize.Width + cheapRadiusBig + cheapRadiusBig, 0), true); var topRightSegment = new ArcSegment(new Point(contentDesiredSize.Width + cheapRadiusBig + cheapRadiusBig + cheapRadiusBig, cheapRadiusSmall), new Size(cheapRadiusBig, cheapRadiusBig), 40, false, SweepDirection.Clockwise, true); triangleX = Math.Tan(radians) * (contentDesiredSize.Height); //triangleX = Math.Tan(radians)*(contentDesiredSize.Height - topRightSegment.Point.Y); var rightSegment = new LineSegment(new Point(topRightSegment.Point.X + triangleX, topRightSegment.Point.Y + contentDesiredSize.Height), true); var bottomRightPoint = new Point(rightSegment.Point.X + cheapRadiusSmall, rightSegment.Point.Y + cheapRadiusSmall); var bottomRightSegment = new ArcSegment(bottomRightPoint, new Size(cheapRadiusSmall, cheapRadiusSmall), 25, false, SweepDirection.Counterclockwise, true); var bottomLeftPoint = new Point(0, bottomRightSegment.Point.Y); var bottomSegment = new LineSegment(bottomLeftPoint, true); var pathSegmentCollection = new PathSegmentCollection { bottomLeftSegment, leftSegment, topLeftSegment, topSegment, topRightSegment, rightSegment, bottomRightSegment, bottomSegment }; var pathFigure = new PathFigure(startPoint, pathSegmentCollection, true) { IsFilled = true }; var pathFigureCollection = new PathFigureCollection { pathFigure }; var geometryGroup = new PathGeometry(pathFigureCollection); geometryGroup.Freeze(); return geometryGroup; }
/// <summary> /// Draw a polygon filled with a gradient of colours. /// </summary> /// <param name="brush"> /// A previously created gradient or image brush (LDShapes.BrushGradient LDShapes.BrushImage). /// </param> /// <param name="points"> /// An array of coordinates for the polygon corners with the form points[i][1] = x, points[i][2] = y. /// /// The number of points must be 3 or more. /// </param> /// <returns> /// None. /// </returns> public static void BrushPolygon(Primitive brush, Primitive points) { Type GraphicsWindowType = typeof(GraphicsWindow); DrawingGroup _mainDrawing; try { _mainDrawing = (DrawingGroup)GraphicsWindowType.GetField("_mainDrawing", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null); InvokeHelper ret = new InvokeHelper(delegate { try { foreach (GradientBrush i in brushes) { if (i.name == brush) { PointCollection _points = getPoints(points); if (_points.Count < 3) return; DrawingContext drawingContext = _mainDrawing.Append(); PathFigure pathFigure = new PathFigure(); pathFigure.IsClosed = true; pathFigure.StartPoint = _points[0]; for (int j = 1; j < _points.Count; j++) { pathFigure.Segments.Add(new LineSegment(_points[j], true)); } PathFigureCollection pathFigureCollection = new PathFigureCollection(); pathFigureCollection.Add(pathFigure); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures = pathFigureCollection; pathGeometry.Freeze(); drawingContext.DrawGeometry(i.getBrush(), null, pathGeometry); drawingContext.Close(); GraphicsWindowType.GetMethod("AddRasterizeOperationToQueue", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).Invoke(null, new object[] { }); } } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } }); FastThread.Invoke(ret); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } }
private void plotLogPoints() { double spanX = Math.Log(2); double spanY = Math.Log(2); setLogAxes(); GeometryGroup s = new GeometryGroup(); PathGeometry pg = new PathGeometry(); PathFigureCollection pfc = new PathFigureCollection(); PathFigure pf = new PathFigure(); PathSegmentCollection psc = new PathSegmentCollection(); Point stpoint = pointslist[0]; stpoint.X = Math.Round(origin.X + spanX * stpoint.X, 2); stpoint.Y = Math.Round(origin.Y - spanY * stpoint.Y, 2); pf.StartPoint = stpoint; EllipseGeometry elg = new EllipseGeometry(stpoint, 2, 2); s.Children.Add(elg); setText(pointToText(stpoint), stpoint); for (int i = 1; i < pointslist.Count; i++) { Point point = pointslist[i]; point.X = Math.Round(origin.X + spanX * point.X, 2); point.Y = Math.Round(origin.Y - spanY * point.Y, 2); LineSegment ls = new LineSegment(point, true); elg = new EllipseGeometry(point, 2, 2); setText(pointToText(point), point); s.Children.Add(elg); psc.Add(ls); spanX = Math.Log(i + 1) * 10; spanY = Math.Log(i + 1) * 10; } pf.Segments = psc; pfc.Add(pf); pg.Figures = pfc; Path p = new Path(); Path p1 = new Path(); p.Data = pg; p.Stroke = Brushes.Green; p1.Data = s; p1.Fill = Brushes.Blue; activeCanvas.Children.Add(p); activeCanvas.Children.Add(p1); activeCanvas.ClipToBounds = true; }
public void plotPoints(List<Point> pointslist) { setAxes(); setXaxisTitle(Xtitle); setYaxisTitle(Ytitle); setPlotTitle(Plottitle); GeometryGroup s = new GeometryGroup(); PathGeometry pg = new PathGeometry(); PathFigureCollection pfc = new PathFigureCollection(); PathFigure pf = new PathFigure(); PathSegmentCollection psc = new PathSegmentCollection(); Point stpoint = pointslist[0]; stpoint.X = origin.X + spanX * stpoint.X; stpoint.Y = origin.Y - spanY * stpoint.Y; pf.StartPoint = stpoint; EllipseGeometry elg = new EllipseGeometry(stpoint, 2, 2); s.Children.Add(elg); string pointText = pointToText(stpoint); setText(pointText, stpoint); for (int i = 1; i < pointslist.Count; i++) { Point point = pointslist[i]; point.X = origin.X + spanX * point.X; point.Y = origin.Y - spanY * point.Y; LineSegment ls = new LineSegment(point, true); elg = new EllipseGeometry(point, 2, 2); setText(pointToText(point), point); s.Children.Add(elg); psc.Add(ls); } pf.Segments = psc; pfc.Add(pf); pg.Figures = pfc; Path p = new Path(); Path p1 = new Path(); p.Data = pg; p.Stroke = Brushes.Green; p1.Data = s; p1.Fill = Brushes.Blue; activeCanvas.Children.Add(p); activeCanvas.Children.Add(p1); activeCanvas.ClipToBounds = true; }