private void RenderArc(double Angle, Path pathRoot, PathFigure pathFigure, ArcSegment arcSegment) { Point startPoint = new Point(Radius, 0); Point endPoint = ComputeCartesianCoordinate(Angle, Radius); endPoint.X += Radius; endPoint.Y += Radius; pathRoot.Width = Radius * 2 + StrokeThickness; pathRoot.Height = Radius * 2 + StrokeThickness; pathRoot.Margin = new Thickness(StrokeThickness, StrokeThickness, 0, 0); bool largeArc = Angle > 180.0; Size outerArcSize = new Size(Radius, Radius); pathFigure.StartPoint = startPoint; if (startPoint.X == Math.Round(endPoint.X) && startPoint.Y == Math.Round(endPoint.Y)) { endPoint.X -= 0.01; } arcSegment.Point = endPoint; arcSegment.Size = outerArcSize; arcSegment.IsLargeArc = largeArc; }
/// <summary> /// Initializes a new instance of the <see cref="Arc"/> class" /// </summary> public Arc() { this.Stroke = new SolidColorBrush(Colors.White); this.StrokeThickness = 2; this.Fill = new SolidColorBrush(Colors.Red); this.UseLayoutRounding = true; this.pathGeometry = new PathGeometry(); this.pathFigure = new PathFigure(); this.pathFigure.IsClosed = true; this.pathFigure.IsFilled = true; this.arcSegment = new ArcSegment(); this.arcSegment.IsLargeArc = false; this.arcSegment.SweepDirection = SweepDirection.Clockwise; this.lineSegment = new LineSegment(); this.pathFigure.Segments.Add(this.arcSegment); this.pathFigure.Segments.Add(this.lineSegment); this.pathGeometry.Figures.Add(this.pathFigure); this.Data = this.pathGeometry; this.ellipseGeometry = new EllipseGeometry(); this.Tapped += this.OnArcTapped; }
public void PlotGrid() { GridLines.Children.Clear(); double xStart = 5; double xEnd = this.ActualWidth - 5; double y = 0; double step = GridLines.ActualHeight / (_numberogGridLines + 1); for (int i = 0; i < _numberogGridLines; i++) { y += step; PathFigure path = new PathFigure(); path.StartPoint = new Point(xStart, y); path.IsClosed = false; LineSegment Line = new LineSegment(); Line.Point = new Point(xEnd, y); path.Segments.Add(Line); PathGeometry myPath = new PathGeometry(); myPath.Figures.Add(path); Path output = new Path(); output.Data = myPath; output.StrokeThickness = 1; output.Stroke = new SolidColorBrush(Windows.UI.Color.FromArgb(100, 150, 150, 150)); GridLines.Children.Add(output); } }
public static Path GetCircleSegment(Point centerPoint, double radius, double angle) { var path = new Path(); var pathGeometry = new PathGeometry(); var circleStart = new Point(centerPoint.X, centerPoint.Y - radius); var arcSegment = new ArcSegment { IsLargeArc = angle > 180.0, Point = ScaleUnitCirclePoint(centerPoint, angle, radius), Size = new Size(radius, radius), SweepDirection = SweepDirection.Clockwise }; var pathFigure = new PathFigure { StartPoint = circleStart, IsClosed = false }; pathFigure.Segments.Add(arcSegment); pathGeometry.Figures.Add(pathFigure); path.Data = pathGeometry; return path; }
protected override void OnNavigatedTo(NavigationEventArgs e) { // Create the AppBarButton for the 'Triangle' command AppBarButton triangle = new AppBarButton(); triangle.Label = "Triangle"; // This button will use the PathIcon class for its icon which allows us to // use vector data to represent the icon PathIcon trianglePathIcon = new PathIcon(); PathGeometry g = new PathGeometry(); g.FillRule = FillRule.Nonzero; // Just create a simple triange shape PathFigure f = new PathFigure(); f.IsFilled = true; f.IsClosed = true; f.StartPoint = new Windows.Foundation.Point(20.0, 5.0); LineSegment s1 = new LineSegment(); s1.Point = new Windows.Foundation.Point(30.0, 30.0); LineSegment s2 = new LineSegment(); s2.Point = new Windows.Foundation.Point(10.0, 30.0); LineSegment s3 = new LineSegment(); s3.Point = new Windows.Foundation.Point(20.0, 5.0); f.Segments.Add(s1); f.Segments.Add(s2); f.Segments.Add(s3); g.Figures.Add(f); trianglePathIcon.Data = g; triangle.Icon = trianglePathIcon; ((CommandBar)BottomAppBar).PrimaryCommands.Insert(2, triangle); }
public Path GetCircleSegment(Point centrePoint, Point currentPoint, double radius, double stripWidth, double angle) { var path = new Path { Stroke = _strokeBrush }; var pathGeometry = new PathGeometry(); var circleStart = new Point(centrePoint.X, centrePoint.Y - radius); // Arc var arcSegment = new ArcSegment { IsLargeArc = angle > 180.0, Point = _mathHelper.ScaleUnitCirclePoint(centrePoint, angle, radius), Size = new Size(radius, radius), SweepDirection = SweepDirection.Clockwise }; //The path figure includes first, the first line from the centre to line1End, then the arc var pathFigure = new PathFigure { StartPoint = circleStart, IsClosed = false }; pathFigure.Segments.Add(arcSegment); pathGeometry.Figures.Add(pathFigure); path.Data = pathGeometry; path.StrokeThickness = stripWidth; return path; }
/// <summary> /// Override for the path's redraw mehtod, controlling how the path is drawns /// </summary> protected override void Redraw() { Debug.Assert(GetValue(StartAngleProperty) != DependencyProperty.UnsetValue); Debug.Assert(GetValue(RadiusProperty) != DependencyProperty.UnsetValue); Debug.Assert(GetValue(AngleProperty) != DependencyProperty.UnsetValue); if (Radius == 0 || !(Thickness > 0)) return; Width = Height = 2 * (Radius); var endAngle = StartAngle + Angle; var smallRadius = Radius - Thickness; var startX = Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius; var startY = Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius; // path container var figure = new PathFigure { StartPoint = new Point(startX, startY), IsClosed = true, IsFilled = true }; // outer arc var outerArcX = Radius + Math.Sin(endAngle * Math.PI / 180) * Radius; var outerArcY = Radius - Math.Cos(endAngle * Math.PI / 180) * Radius; var outerArc = new ArcSegment { IsLargeArc = Angle >= 180.0, Point = new Point(outerArcX, outerArcY), Size = new Size(Radius, Radius), SweepDirection = SweepDirection.Clockwise, }; figure.Segments.Add(outerArc); // start angle line var lineX = smallRadius + Math.Sin(endAngle * Math.PI / 180) * smallRadius; var lineY = smallRadius - Math.Cos(endAngle * Math.PI / 180) * smallRadius; var line = new LineSegment { Point = new Point(lineX + Thickness, lineY + Thickness) }; figure.Segments.Add(line); // inner arc var innerArcX = smallRadius + Math.Sin(StartAngle * Math.PI / 180) * smallRadius ; var innerArcY = smallRadius - Math.Cos(StartAngle * Math.PI / 180) * smallRadius; var innerArc = new ArcSegment { IsLargeArc = Angle >= 180.0, Point = new Point(innerArcX + Thickness, innerArcY + Thickness), Size = new Size(smallRadius, smallRadius), SweepDirection = SweepDirection.Counterclockwise, }; figure.Segments.Add(innerArc); Data = new PathGeometry { Figures = { figure } }; InvalidateArrange(); }
public PieSlice() { pathFigure = new PathFigure { IsClosed = false ,IsFilled = false}; arcSegment = new ArcSegment { SweepDirection = SweepDirection.Clockwise }; pathFigure.Segments.Add(arcSegment); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); this.Data = pathGeometry; UpdateValues(); }
public Sticker(Point Location, Double Radius) { PathFigure figure = new PathFigure(); PathGeometry geo = new PathGeometry(); geo.Figures.Add(figure); this.Data = geo; this.Location = Location; this.Radius = Radius; this.Tapped += Sticker_Tapped; this.Holding += Sticker_Holding; this.ManipulationMode = Windows.UI.Xaml.Input.ManipulationModes.All; }
private PathFigure BuildStrand(double startAngle, int indx, double inc) { // now build strand start with first point PathFigure pf = new PathFigure(); int currentStrand = indx; // now loop through perms foreach (Permutation p in bd.Perms) { // point for start of perm int pindx = bd.Perms.IndexOf(p); double x1 = pindx; double x2 = x1 + 1; double sangle = startAngle + colAngle * x1; double y1 = bd.ToolPosition - currentStrand * rowHeight; if (pindx == 0) { pf.StartPoint = new Point(y1 * Math.Cos(sangle), y1 * Math.Sin(sangle)); } int nxtStrand = p.PermOf(currentStrand); double eangle = sangle + colAngle; double y2 = bd.ToolPosition - nxtStrand * rowHeight; PolyLineSegment pls = new PolyLineSegment(); double i = 0; for (i = 0; i < 1.0; i += inc) { if (p.IsNoChange) { double a = sangle + i * colAngle; Point pnt = new Point(y1 * Math.Cos(a), y1 * Math.Sin(a)); pls.Points.Add(pnt); } else pls.Points.Add(Interp(x1, y1, i, x2, y2, sangle)); } if (p.IsNoChange) { double a = sangle + 1.0 * colAngle; Point pnt = new Point(y1 * Math.Cos(a), y1 * Math.Sin(a)); pls.Points.Add(pnt); } else pls.Points.Add(Interp(x1, y1, 1.0, x2, y2, sangle)); pf.Segments.Add(pls); currentStrand = nxtStrand; } return pf; }
public PathGeometry Pattern() { PathGeometry geo = new PathGeometry(); PathFigure figure = new PathFigure(); geo.Figures.Add(figure); figure.StartPoint = new Point(Info[0].X, Info[0].Y); for (int i = 0; i < Arcs; i++) { ArcData a = Info[(i + 1) % Arcs] as ArcData; figure.Segments.Add(new ArcSegment { Point = new Point(a.X, a.Y), Size = new Size(a.SizeX, a.SizeY), IsLargeArc = a.IsLarge, RotationAngle = a.Rotation, SweepDirection = a.SweepDirection }); } return geo; }
public static void AddPathFigure( this D2D.GeometrySink sink, Jupiter.Media.PathFigure pathFigure) { sink.BeginFigure( pathFigure.StartPoint.ToSharpDX(), pathFigure.IsFilled ? D2D.FigureBegin.Filled : D2D.FigureBegin.Hollow); foreach (var segment in pathFigure.Segments) { sink.AddPathFigureSegment(segment); } sink.EndFigure(pathFigure.IsClosed ? D2D.FigureEnd.Closed : D2D.FigureEnd.Open); }
public PiePath() { pathFigure = new PathFigure { IsClosed = true }; lineSegment = new LineSegment(); arcSegment = new ArcSegment { SweepDirection = SweepDirection.Clockwise }; pathFigure.Segments.Add(lineSegment); pathFigure.Segments.Add(arcSegment); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); this.Data = pathGeometry; UpdateValues(); }
private PathFigure Parse(String Data) { List<List<String>> Split = Spliter(Data); PathFigure figure = new PathFigure(); foreach (List<String> item in Split) { switch (item[0]) { case "M": figure.StartPoint = new Point(Double.Parse(item[1]), Double.Parse(item[2])); for (int i = 3; i < item.Count;) figure.Segments.Add(new LineSegment { Point = new Point(Double.Parse(item[i++]), Double.Parse(item[i++])) }); break; case "L": for (int i = 1; i < item.Count;) figure.Segments.Add(new LineSegment { Point = new Point(Double.Parse(item[i++]), Double.Parse(item[i++])) }); break; case "H": for (int i = 1; i < item.Count;) figure.Segments.Add(new LineSegment { Point = new Point(Double.Parse(item[i++]), (figure.Segments[figure.Segments.Count - 1] as LineSegment).Point.Y) }); break; case "V": for (int i = 1; i < item.Count;) figure.Segments.Add(new LineSegment { Point = new Point((figure.Segments[figure.Segments.Count - 1] as LineSegment).Point.X, Double.Parse(item[i++])) }); break; case "C": for (int i = 1; i < item.Count;) figure.Segments.Add(new BezierSegment { Point1 = new Point(Double.Parse(item[i++]), Double.Parse(item[i++])), Point2 = new Point(Double.Parse(item[i++]), Double.Parse(item[i++])), Point3 = new Point(Double.Parse(item[i++]), Double.Parse(item[i++])) }); break; case "Q": for (int i = 1; i < item.Count;) figure.Segments.Add(new QuadraticBezierSegment { Point1 = new Point(Double.Parse(item[i++]), Double.Parse(item[i++])), Point2 = new Point(Double.Parse(item[i++]), Double.Parse(item[i++])) }); break; case "S": throw new NotImplementedException(); case "T": throw new NotImplementedException(); case "A": for (int i = 1; i < item.Count;) figure.Segments.Add(new ArcSegment { Size = new Size(Double.Parse(item[i++]), Double.Parse(item[i++])), RotationAngle = Double.Parse(item[i++]), IsLargeArc = (Double.Parse(item[i++]) == 1.0), SweepDirection = Double.Parse(item[i++]) == 1.0 ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, Point = new Point(Double.Parse(item[i++]), Double.Parse(item[i++]))}); break; case "Z": figure.IsClosed = true; break; } } return figure; }
public void UpdatePath() { // ensure variables if (GetValue(StartAngleProperty) == DependencyProperty.UnsetValue) throw new ArgumentNullException("Start Angle is required"); if (GetValue(RadiusProperty) == DependencyProperty.UnsetValue) throw new ArgumentNullException("Radius is required"); if (GetValue(AngleProperty) == DependencyProperty.UnsetValue) throw new ArgumentNullException("Angle is required"); Width = Height = 2 * (Radius + StrokeThickness); var endAngle = StartAngle + Angle; // path container var figureP = new Point(Radius, Radius); var figure = new PathFigure { StartPoint = figureP, IsClosed = true, }; // start angle line var lineX = Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius; var lineY = Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius; var lineP = new Point(lineX, lineY); var line = new LineSegment { Point = lineP }; figure.Segments.Add(line); // outer arc var arcX = Radius + Math.Sin(endAngle * Math.PI / 180) * Radius; var arcY = Radius - Math.Cos(endAngle * Math.PI / 180) * Radius; var arcS = new Size(Radius, Radius); var arcP = new Point(arcX, arcY); var arc = new ArcSegment { IsLargeArc = Angle >= 180.0, Point = arcP, Size = arcS, SweepDirection = SweepDirection.Clockwise, }; figure.Segments.Add(arc); // finalé Data = new PathGeometry { Figures = { figure } }; InvalidateArrange(); }
public void SetMouth() { int index = _laugh ? 0 : 1; var figure = new PathFigure() { StartPoint = _mouthPoints[index, 0] }; figure.Segments = new PathSegmentCollection(); var segment1 = new QuadraticBezierSegment(); segment1.Point1 = _mouthPoints[index, 1]; segment1.Point2 = _mouthPoints[index, 2]; figure.Segments.Add(segment1); var geometry = new PathGeometry(); geometry.Figures = new PathFigureCollection(); geometry.Figures.Add(figure); mouth.Data = geometry; _laugh = !_laugh; }
public CurvePanel() { _bgcanvas = new Canvas(); _bgcanvas.VerticalAlignment = VerticalAlignment.Stretch; _bgcanvas.HorizontalAlignment = HorizontalAlignment.Stretch; _path = new Path(); _path.Stroke = Stroke; _path.StrokeThickness = StrokeThickness; PathGeometry geo = new PathGeometry(); _bfigure = new PathFigure(); _bseg = new BezierSegment(); _bfigure.Segments.Add(_bseg); geo.Figures.Add(_bfigure); _path.Data = geo; _bgcanvas.Children.Add(_path); this.Children.Add(_bgcanvas); this.SizeChanged += OnSizeChanged; }
private static PathGeometry CloneDeep(PathGeometry pathGeometry) { var newPathGeometry = new PathGeometry(); foreach (var figure in pathGeometry.Figures) { var newFigure = new PathFigure(); newFigure.StartPoint = figure.StartPoint; foreach (var segment in figure.Segments) { var segmentAsPolyLineSegment = segment as PolyLineSegment; if (segmentAsPolyLineSegment != null) { var newSegment = new PolyLineSegment(); foreach (var point in segmentAsPolyLineSegment.Points) { newSegment.Points.Add(point); } newFigure.Segments.Add(newSegment); } var segmentLineSegment = segment as LineSegment; if (segmentLineSegment != null) { var newSegment = new LineSegment(); newSegment.Point = new Point(segmentLineSegment.Point.X, segmentLineSegment.Point.Y); newFigure.Segments.Add(newSegment); } var segmentBezierSegment = segment as BezierSegment; if (segmentBezierSegment != null) { var newSegment = new BezierSegment(); newSegment.Point1 = new Point(segmentBezierSegment.Point1.X, segmentBezierSegment.Point1.Y); newSegment.Point2 = new Point(segmentBezierSegment.Point2.X, segmentBezierSegment.Point2.Y); newSegment.Point3 = new Point(segmentBezierSegment.Point3.X, segmentBezierSegment.Point3.Y); newFigure.Segments.Add(newSegment); } } newPathGeometry.Figures.Add(newFigure); } return newPathGeometry; }
/// <summary> /// Override for the path's redraw mehtod, controlling how the path is drawns /// </summary> protected override void Redraw() { Debug.Assert(GetValue(StartAngleProperty) != DependencyProperty.UnsetValue); Debug.Assert(GetValue(RadiusProperty) != DependencyProperty.UnsetValue); Debug.Assert(GetValue(AngleProperty) != DependencyProperty.UnsetValue); Width = Height = 2 * (Radius); var endAngle = StartAngle + Angle; // path container var figure = new PathFigure { StartPoint = new Point(Radius, Radius), IsClosed = true, IsFilled = true }; // start angle line var lineX = Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius; var lineY = Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius; var line = new LineSegment { Point = new Point(lineX, lineY) }; figure.Segments.Add(line); // outer arc var arcX = Radius + Math.Sin(endAngle * Math.PI / 180) * Radius; var arcY = Radius - Math.Cos(endAngle * Math.PI / 180) * Radius; var arc = new ArcSegment { IsLargeArc = Angle >= 180.0, Point = new Point(arcX, arcY), Size = new Size(Radius, Radius), SweepDirection = SweepDirection.Clockwise, }; figure.Segments.Add(arc); Data = new PathGeometry { Figures = { figure } }; InvalidateArrange(); }
public static Geometry CreateArcGeometry(double minAngle, double maxAngle, double radius, int thickness, SweepDirection sweepDirection) { //the range will have 4 segments (arc, line, arc, line) //if the sweep angle is bigger than 180 use the large arc //first use the same sweep direction as the control. invert for the second arc. PathFigure figure = new PathFigure(); figure.IsClosed = true; figure.StartPoint = new Point((radius - thickness) * Math.Sin(minAngle * Math.PI / 180), -(radius - thickness) * Math.Cos(minAngle * Math.PI / 180)); //first arc segment ArcSegment arc = new ArcSegment(); arc.Point = new Point((radius - thickness) * Math.Sin(maxAngle * Math.PI / 180), -(radius - thickness) * Math.Cos(maxAngle * Math.PI / 180)); arc.Size = new Size(radius - thickness, radius - thickness); arc.SweepDirection = sweepDirection; if (Math.Abs(maxAngle - minAngle) > 180) arc.IsLargeArc = true; figure.Segments.Add(arc); //first line segment LineSegment line = new LineSegment(); line.Point = new Point(radius * Math.Sin(maxAngle * Math.PI / 180), -radius * Math.Cos(maxAngle * Math.PI / 180)); figure.Segments.Add(line); //second arc segment arc = new ArcSegment(); arc.Point = new Point(radius * Math.Sin(minAngle * Math.PI / 180), -radius * Math.Cos(minAngle * Math.PI / 180)); arc.Size = new Size(radius, radius); arc.SweepDirection = SweepDirection.Counterclockwise; if (sweepDirection == SweepDirection.Counterclockwise) arc.SweepDirection = SweepDirection.Clockwise; if (Math.Abs(maxAngle - minAngle) > 180) arc.IsLargeArc = true; figure.Segments.Add(arc); PathGeometry path = new PathGeometry(); path.Figures.Add(figure); return path; }
/// <summary> /// Updates the PieDataPoint's Geometry property. /// </summary> /// <param name="pieDataPoint">PieDataPoint instance.</param> /// <param name="plotAreaWidth">PlotArea width.</param> /// <param name="plotAreaHeight">PlotArea height.</param> internal static void UpdatePieDataPointGeometry(PieDataPoint pieDataPoint, double plotAreaWidth, double plotAreaHeight) { double diameter = (plotAreaWidth < plotAreaHeight) ? plotAreaWidth : plotAreaHeight; diameter *= 0.95; double plotAreaRadius = diameter / 2; double maxDistanceFromCenter = 0.0; double sliceRadius = plotAreaRadius - maxDistanceFromCenter; Point translatePoint = new Point(plotAreaWidth / 2, plotAreaHeight / 2); if (pieDataPoint.ActualRatio == 1) { foreach (DependencyProperty dependencyProperty in new DependencyProperty[] { PieDataPoint.GeometryProperty, PieDataPoint.GeometrySelectionProperty, PieDataPoint.GeometryHighlightProperty }) { Geometry geometry = new EllipseGeometry { Center = translatePoint, RadiusX = sliceRadius, RadiusY = sliceRadius }; pieDataPoint.SetValue(dependencyProperty, geometry); } } else { if (pieDataPoint.ActualRatio == 0.0) { pieDataPoint.Geometry = null; pieDataPoint.GeometryHighlight = null; pieDataPoint.GeometrySelection = null; } else { double ratio = pieDataPoint.ActualRatio; double offsetRatio = pieDataPoint.ActualOffsetRatio; double currentRatio = offsetRatio + ratio; Point offsetRatioPoint = ConvertRatioOfRotationToPoint(offsetRatio, sliceRadius, sliceRadius); Point adjustedOffsetRatioPoint = offsetRatioPoint.Translate(translatePoint); // Calculate the last clockwise point in the pie slice Point currentRatioPoint = ConvertRatioOfRotationToPoint(currentRatio, sliceRadius, sliceRadius); // Adjust point using center of plot area as origin // instead of 0,0 Point adjustedCurrentRatioPoint = currentRatioPoint.Translate(translatePoint); foreach (DependencyProperty dependencyProperty in new DependencyProperty[] { PieDataPoint.GeometryProperty, PieDataPoint.GeometrySelectionProperty, PieDataPoint.GeometryHighlightProperty }) { // Creating the pie slice geometry object PathFigure pathFigure = new PathFigure { IsClosed = true }; pathFigure.StartPoint = translatePoint; pathFigure.Segments.Add(new LineSegment { Point = adjustedOffsetRatioPoint }); bool isLargeArc = (currentRatio - offsetRatio) > 0.5; pathFigure.Segments.Add( new ArcSegment { Point = adjustedCurrentRatioPoint, IsLargeArc = isLargeArc, Size = new Size(sliceRadius, sliceRadius), SweepDirection = SweepDirection.Clockwise }); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); pieDataPoint.SetValue(dependencyProperty, pathGeometry); } } } }
private void UpdatePath() { var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure(); pathFigure.StartPoint = new Point(Radius, Radius); pathFigure.IsClosed = true; // Starting Point var lineSegment = new LineSegment { Point = new Point( Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius, Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius) }; // Arc var arcSegment = new ArcSegment(); arcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0; arcSegment.Point = new Point( Radius + Math.Sin(EndAngle * Math.PI / 180) * Radius, Radius - Math.Cos(EndAngle * Math.PI / 180) * Radius); arcSegment.Size = new Size(Radius, Radius); arcSegment.SweepDirection = SweepDirection.Clockwise; pathFigure.Segments.Add(lineSegment); pathFigure.Segments.Add(arcSegment); pathGeometry.Figures.Add(pathFigure); this.Data = pathGeometry; this.InvalidateArrange(); }
private void NodeLinked(NodeConnection from, NodeConnection to) { Debug.WriteLine("Linked {0} -> {1}", from.ConnectedNodeId, to.ConnectedNodeId); NodeBase nodeFrom = null; NodeBase nodeTo = null; foreach (var child in this.canvasDiagram.Children) { if (child is NodeBase) { var node = child as NodeBase; if (node.NodeId == from.ConnectedNodeId) { nodeFrom = node; } if (node.NodeId == to.ConnectedNodeId) { nodeTo = node; } } } var fromPoint = nodeFrom.GetPosition(); var toPoint = nodeTo.GetPosition(); Point distance = new Point(toPoint.X - fromPoint.X, toPoint.Y - fromPoint.Y); BezierSegment segment = new BezierSegment(); segment.Point1 = new Point(fromPoint.X + distance.X / 3, fromPoint.Y - 100); segment.Point2 = new Point(fromPoint.X + distance.X * 2 / 3, toPoint.Y + 100); segment.Point3 = nodeTo.GetPosition(); PathFigure figure = new PathFigure(); figure.StartPoint = nodeFrom.GetPosition(); figure.Segments.Add(segment); PathGeometry geo = new PathGeometry(); geo.Figures.Add(figure); Windows.UI.Xaml.Shapes.Path path = new Windows.UI.Xaml.Shapes.Path(); path.StrokeThickness = 2; path.Stroke = new SolidColorBrush(Colors.Black); path.Data = geo; this.canvasDiagram.Children.Add(path); }
private void DrawChart() { if ((dataSet != null) && (dataSet.Length > 0)) { var path = new Windows.UI.Xaml.Shapes.Path(); path.Stroke = chartColor; path.StrokeThickness = 15; path.StrokeLineJoin = PenLineJoin.Round; path.StrokeStartLineCap = PenLineCap.Round; path.StrokeEndLineCap = PenLineCap.Round; var geometry = new PathGeometry(); var figure = new PathFigure(); figure.IsClosed = false; figure.StartPoint = new Point(offsetList[0].OffsetX, offsetList[0].OffsetY); for (int i = 0; i < offsetList.Count; i++) { var segment = new LineSegment(); segment.Point = new Point(offsetList[i].OffsetX, offsetList[i].OffsetY); figure.Segments.Add(segment); } geometry.Figures.Add(figure); path.Data = geometry; Children.Add(path); } }
private void UpdatePath() { var radius = this.Radius - this.StrokeThickness / 2; if (_isUpdating || this.ActualWidth == 0 || radius <= 0) { return; } var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure(); pathFigure.StartPoint = new Point(radius, radius); pathFigure.IsClosed = true; // Starting Point var lineSegment = new LineSegment { Point = new Point( radius + Math.Sin(StartAngle * Math.PI / 180) * radius, radius - Math.Cos(StartAngle * Math.PI / 180) * radius) }; // Arc var arcSegment = new ArcSegment(); arcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0; arcSegment.Point = new Point( radius + Math.Sin(EndAngle * Math.PI / 180) * radius, radius - Math.Cos(EndAngle * Math.PI / 180) * radius); arcSegment.Size = new Size(radius, radius); arcSegment.SweepDirection = SweepDirection.Clockwise; pathFigure.Segments.Add(lineSegment); pathFigure.Segments.Add(arcSegment); pathGeometry.Figures.Add(pathFigure); this.Data = pathGeometry; this.InvalidateArrange(); }
public object ConvertToNative(Geometry geometry) { winMedia.Geometry winGeometry = null; // Determine what type of geometry we're dealing with. if (geometry is LineGeometry) { LineGeometry xamGeometry = geometry as LineGeometry; winGeometry = new winMedia.LineGeometry { StartPoint = ConvertPoint(xamGeometry.StartPoint), EndPoint = ConvertPoint(xamGeometry.EndPoint) }; } else if (geometry is RectangleGeometry) { Rect rect = (geometry as RectangleGeometry).Rect; winGeometry = new winMedia.RectangleGeometry { Rect = new winFound.Rect(rect.X, rect.Y, rect.Width, rect.Height) }; } else if (geometry is EllipseGeometry) { EllipseGeometry xamGeometry = geometry as EllipseGeometry; winGeometry = new winMedia.EllipseGeometry { Center = ConvertPoint(xamGeometry.Center), RadiusX = xamGeometry.RadiusX, RadiusY = xamGeometry.RadiusY }; } else if (geometry is GeometryGroup) { GeometryGroup xamGeometry = geometry as GeometryGroup; winGeometry = new winMedia.GeometryGroup { FillRule = ConvertFillRule(xamGeometry.FillRule) }; foreach (Geometry xamChild in xamGeometry.Children) { winMedia.Geometry winChild = ConvertToNative(xamChild) as winMedia.Geometry; (winGeometry as winMedia.GeometryGroup).Children.Add(winChild); } } else if (geometry is PathGeometry) { PathGeometry xamPathGeometry = geometry as PathGeometry; winMedia.PathGeometry winPathGeometry = new winMedia.PathGeometry { FillRule = ConvertFillRule(xamPathGeometry.FillRule) }; foreach (PathFigure xamPathFigure in xamPathGeometry.Figures) { winMedia.PathFigure winPathFigure = new winMedia.PathFigure { StartPoint = ConvertPoint(xamPathFigure.StartPoint), IsFilled = xamPathFigure.IsFilled, IsClosed = xamPathFigure.IsClosed }; winPathGeometry.Figures.Add(winPathFigure); foreach (PathSegment xamPathSegment in xamPathFigure.Segments) { // LineSegment if (xamPathSegment is LineSegment) { LineSegment xamSegment = xamPathSegment as LineSegment; winMedia.LineSegment winSegment = new winMedia.LineSegment { Point = ConvertPoint(xamSegment.Point) }; winPathFigure.Segments.Add(winSegment); } // PolylineSegment if (xamPathSegment is PolyLineSegment) { PolyLineSegment xamSegment = xamPathSegment as PolyLineSegment; winMedia.PolyLineSegment winSegment = new winMedia.PolyLineSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // BezierSegment if (xamPathSegment is BezierSegment) { BezierSegment xamSegment = xamPathSegment as BezierSegment; winMedia.BezierSegment winSegment = new winMedia.BezierSegment { Point1 = ConvertPoint(xamSegment.Point1), Point2 = ConvertPoint(xamSegment.Point2), Point3 = ConvertPoint(xamSegment.Point3) }; winPathFigure.Segments.Add(winSegment); } // PolyBezierSegment else if (xamPathSegment is PolyBezierSegment) { PolyBezierSegment xamSegment = xamPathSegment as PolyBezierSegment; winMedia.PolyBezierSegment winSegment = new winMedia.PolyBezierSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // QuadraticBezierSegment if (xamPathSegment is QuadraticBezierSegment) { QuadraticBezierSegment xamSegment = xamPathSegment as QuadraticBezierSegment; winMedia.QuadraticBezierSegment winSegment = new winMedia.QuadraticBezierSegment { Point1 = ConvertPoint(xamSegment.Point1), Point2 = ConvertPoint(xamSegment.Point2), }; winPathFigure.Segments.Add(winSegment); } // PolyQuadraticBezierSegment else if (xamPathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment xamSegment = xamPathSegment as PolyQuadraticBezierSegment; winMedia.PolyQuadraticBezierSegment winSegment = new winMedia.PolyQuadraticBezierSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // ArcSegment else if (xamPathSegment is ArcSegment) { ArcSegment xamSegment = xamPathSegment as ArcSegment; winMedia.ArcSegment winSegment = new winMedia.ArcSegment(); winSegment.Size = new winFound.Size(xamSegment.Size.Width, xamSegment.Size.Height); winSegment.RotationAngle = xamSegment.RotationAngle; winSegment.IsLargeArc = xamSegment.IsLargeArc; winSegment.SweepDirection = xamSegment.SweepDirection == SweepDirection.Clockwise ? winMedia.SweepDirection.Clockwise : winMedia.SweepDirection.Counterclockwise; winSegment.Point = ConvertPoint(xamSegment.Point); winPathFigure.Segments.Add(winSegment); } } } winGeometry = winPathGeometry; } // Set transform. if (geometry.Transform != null) { winGeometry.Transform = (winMedia.Transform)geometry.Transform.GetNativeObject(); } return(winGeometry); }
public static void Write(this StreamGeometryContext ctx, PathFigure pathFigure) { ctx.BeginFigure(pathFigure.StartPoint, pathFigure.IsFilled, pathFigure.IsClosed); pathFigure.Segments.ForEach(ctx.Write); ctx.SetClosedState(pathFigure.IsClosed); }
/// <summary> /// The draw line segments. /// </summary> /// <param name="points"> /// The points. /// </param> /// <param name="stroke"> /// The stroke. /// </param> /// <param name="thickness"> /// The thickness. /// </param> /// <param name="dashArray"> /// The dash array. /// </param> /// <param name="lineJoin"> /// The line join. /// </param> /// <param name="aliased"> /// The aliased. /// </param> public void DrawLineSegments( IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased) { var path = new Path(); this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased); var pg = new PathGeometry(); for (int i = 0; i + 1 < points.Count; i += 2) { // if (points[i].Y==points[i+1].Y) // { // var line = new Line(); // line.X1 = 0.5+(int)points[i].X; // line.X2 = 0.5+(int)points[i+1].X; // line.Y1 = 0.5+(int)points[i].Y; // line.Y2 = 0.5+(int)points[i+1].Y; // SetStroke(line, OxyColors.DarkRed, thickness, lineJoin, dashArray, aliased); // Add(line); // continue; // } var figure = new PathFigure { StartPoint = points[i].ToPoint(aliased), IsClosed = false }; figure.Segments.Add(new LineSegment { Point = points[i + 1].ToPoint(aliased) }); pg.Figures.Add(figure); } path.Data = pg; this.Add(path); }
/// <summary> /// The draw polygons. /// </summary> /// <param name="polygons"> /// The polygons. /// </param> /// <param name="fill"> /// The fill. /// </param> /// <param name="stroke"> /// The stroke. /// </param> /// <param name="thickness"> /// The thickness. /// </param> /// <param name="dashArray"> /// The dash array. /// </param> /// <param name="lineJoin"> /// The line join. /// </param> /// <param name="aliased"> /// The aliased. /// </param> public void DrawPolygons( IList<IList<ScreenPoint>> polygons, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased) { var path = new Path(); this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased); if (fill != null) { path.Fill = this.GetCachedBrush(fill); } var pg = new PathGeometry { FillRule = FillRule.Nonzero }; foreach (var polygon in polygons) { var figure = new PathFigure { IsClosed = true }; bool first = true; foreach (ScreenPoint p in polygon) { if (first) { figure.StartPoint = p.ToPoint(aliased); first = false; } else { figure.Segments.Add(new LineSegment { Point = p.ToPoint(aliased) }); } } pg.Figures.Add(figure); } path.Data = pg; this.Add(path); }
public void InitializePieChart() { // draw the full circle/arc _arcSegment360 = new ArcSegment { SweepDirection = SweepDirection.Clockwise }; _pathFigure360 = new PathFigure { Segments = new PathSegmentCollection { _arcSegment360 } }; _pathRoot360 = new Path { Stroke = Segment360Color, StrokeThickness = StrokeThickness, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Data = new PathGeometry { Figures = new PathFigureCollection { _pathFigure360 } } }; //draw a circle with the given angle _arcSegment = new ArcSegment { SweepDirection = SweepDirection.Clockwise }; _pathFigure = new PathFigure { Segments = new PathSegmentCollection { _arcSegment } }; _pathRoot = new Path { Stroke = SegmentColor, StrokeThickness = StrokeThickness, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Data = new PathGeometry { Figures = new PathFigureCollection { _pathFigure } } }; Content = new Grid { Background = BackgroundColor, Children = { _pathRoot360, _pathRoot, } }; }
private void DrawEWNS_map() { if (this.Longitudes.Count() < 4 || this.Latitudes.Count() < 4) { return; } Size size = this.m_renderSize;// this.grdHostGrid.RenderSize; float[] ews = this.m_longitudes; float[] nss = this.m_latitudes; GeometryGroup rootGroup = new GeometryGroup(); //创建起点和终点 float startX = ews.First(); float startY = nss.First(); rootGroup.Children.Add(new EllipseGeometry() { Center = new Point(startX, startY), RadiusX = 10, RadiusY = 10 }); rootGroup.Children.Add(new EllipseGeometry() { Center = new Point(startX, startY), RadiusX = 8, RadiusY = 8 }); PathGeometry pg = new PathGeometry() { Figures = new PathFigureCollection() }; PathFigure figure = new PathFigure() { IsClosed = false, StartPoint = new Point(startX, startY) }; figure.IsFilled = false; PolyBezierSegment segments = this.CreateSegments(ews, nss); figure.Segments.Add(segments); pg.Figures.Add(figure); rootGroup.Children.Add(pg); this.grdHostGrid.Data = rootGroup; }
private void VisualizeGraph(RainData rainData, bool animated = true) { List<int> pointValues; if (rainData == null || rainData.Points == null) pointValues = new List<int>(); else pointValues = rainData.Points.Take(25).Select(p => p.AdjustedValue).ToList(); while (pointValues.Count < 25) pointValues.Add(pointValues.LastOrDefault()); var path = GraphView.Data as PathGeometry; var graphSize = new Size(GraphContainer.ActualWidth, GraphContainer.ActualHeight); var step = graphSize.Width / Model.Entries; Func<int, double> xForIndex = idx => idx == 0 ? -2 : idx * step; var x = 0; var max = (graphSize.Height / 12.0 * 11.0) - 10; var allZeros = pointValues.Take(Model.Entries + 1).All(p => p == 0); var points = pointValues.Select(v => { var y = allZeros ? max - 20 : Math.Max(1, max - (v * max / 100)); var p = new Point(xForIndex(x), y); x++; return p; }).ToList(); points.Add(new Point(graphSize.Width + 2, points.Last().Y)); points.Add(new Point(graphSize.Width + 2, graphSize.Height + 2)); PathFigure figure; var startPoint = new Point(-2.0, graphSize.Height + 2); if (path == null) { path = new PathGeometry(); figure = new PathFigure() { StartPoint = startPoint, IsClosed = true }; path.Figures.Add(figure); foreach (var p in points) { figure.Segments.Add(new LineSegment() { Point = p }); } GraphView.Data = path; } var entriesAnimated = graphEntries != Model.Entries && graphEntries > 0 && Model.Entries > 0; if (entriesAnimated) UpdateEntriesImage(); var ms300 = TimeSpan.FromMilliseconds(entriesAnimated ? 450 / Math.Abs(Model.Entries - graphEntries) : animated ? 300 : 0); graphEntries = Model.Entries; var storyboard = new Storyboard() { Duration = ms300 }; figure = path.Figures[0]; var anim = new PointAnimation() { Duration = ms300, To = startPoint, FillBehavior = FillBehavior.HoldEnd, EnableDependentAnimation = true }; Storyboard.SetTarget(anim, figure); Storyboard.SetTargetProperty(anim, "StartPoint"); storyboard.Children.Add(anim); for (var i = 0; i < points.Count; ++i) { anim = new PointAnimation() { Duration = ms300, To = points[i], FillBehavior = FillBehavior.HoldEnd, EnableDependentAnimation = true }; Storyboard.SetTarget(anim, figure.Segments[i]); Storyboard.SetTargetProperty(anim, "Point"); storyboard.Children.Add(anim); } var strokeAnim = new ColorAnimation() { Duration = ms300, FillBehavior = FillBehavior.HoldEnd, To = allZeros ? Colors.Transparent : graphStrokeColor, EnableDependentAnimation = true }; Storyboard.SetTarget(strokeAnim, GraphView.Stroke); Storyboard.SetTargetProperty(strokeAnim, "Color"); storyboard.Children.Add(strokeAnim); var fillTopAnim = new ColorAnimation() { Duration = ms300, FillBehavior = FillBehavior.HoldEnd, To = allZeros ? Colors.Black : graphFillFrom, EnableDependentAnimation = true }; Storyboard.SetTarget(fillTopAnim, ((LinearGradientBrush)GraphView.Fill).GradientStops[0]); Storyboard.SetTargetProperty(fillTopAnim, "Color"); storyboard.Children.Add(fillTopAnim); storyboard.Begin(() => GraphView.Data = path); }
public static WMedia.Geometry ToWindows(this Geometry geometry) { WMedia.Geometry wGeometry = null; if (geometry is LineGeometry) { LineGeometry lineGeometry = geometry as LineGeometry; wGeometry = new WMedia.LineGeometry { StartPoint = lineGeometry.StartPoint.ToWindows(), EndPoint = lineGeometry.EndPoint.ToWindows() }; } else if (geometry is RectangleGeometry) { var rect = (geometry as RectangleGeometry).Rect; wGeometry = new WMedia.RectangleGeometry { Rect = new WFoundation.Rect(rect.X, rect.Y, rect.Width, rect.Height) }; } else if (geometry is EllipseGeometry) { EllipseGeometry ellipseGeometry = geometry as EllipseGeometry; wGeometry = new WMedia.EllipseGeometry { Center = ellipseGeometry.Center.ToWindows(), RadiusX = ellipseGeometry.RadiusX, RadiusY = ellipseGeometry.RadiusY }; } else if (geometry is GeometryGroup) { GeometryGroup geometryGroup = geometry as GeometryGroup; wGeometry = new WMedia.GeometryGroup { FillRule = ConvertFillRule(geometryGroup.FillRule) }; foreach (Geometry children in geometryGroup.Children) { WMedia.Geometry winChild = children.ToWindows(); (wGeometry as WMedia.GeometryGroup).Children.Add(winChild); } } else if (geometry is PathGeometry) { PathGeometry pathGeometry = geometry as PathGeometry; WMedia.PathGeometry wPathGeometry = new WMedia.PathGeometry { FillRule = ConvertFillRule(pathGeometry.FillRule) }; foreach (PathFigure xamPathFigure in pathGeometry.Figures) { WMedia.PathFigure wPathFigure = new WMedia.PathFigure { StartPoint = xamPathFigure.StartPoint.ToWindows(), IsFilled = xamPathFigure.IsFilled, IsClosed = xamPathFigure.IsClosed }; wPathGeometry.Figures.Add(wPathFigure); foreach (PathSegment pathSegment in xamPathFigure.Segments) { // LineSegment if (pathSegment is LineSegment) { LineSegment lineSegment = pathSegment as LineSegment; WMedia.LineSegment winSegment = new WMedia.LineSegment { Point = lineSegment.Point.ToWindows() }; wPathFigure.Segments.Add(winSegment); } // PolylineSegment if (pathSegment is PolyLineSegment) { PolyLineSegment polyLineSegment = pathSegment as PolyLineSegment; WMedia.PolyLineSegment wSegment = new WMedia.PolyLineSegment(); foreach (var point in polyLineSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // BezierSegment if (pathSegment is BezierSegment) { BezierSegment bezierSegment = pathSegment as BezierSegment; WMedia.BezierSegment wSegment = new WMedia.BezierSegment { Point1 = bezierSegment.Point1.ToWindows(), Point2 = bezierSegment.Point2.ToWindows(), Point3 = bezierSegment.Point3.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyBezierSegment else if (pathSegment is PolyBezierSegment) { PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; WMedia.PolyBezierSegment wSegment = new WMedia.PolyBezierSegment(); foreach (var point in polyBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // QuadraticBezierSegment if (pathSegment is QuadraticBezierSegment) { QuadraticBezierSegment quadraticBezierSegment = pathSegment as QuadraticBezierSegment; WMedia.QuadraticBezierSegment wSegment = new WMedia.QuadraticBezierSegment { Point1 = quadraticBezierSegment.Point1.ToWindows(), Point2 = quadraticBezierSegment.Point2.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyQuadraticBezierSegment else if (pathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment polyQuadraticBezierSegment = pathSegment as PolyQuadraticBezierSegment; WMedia.PolyQuadraticBezierSegment wSegment = new WMedia.PolyQuadraticBezierSegment(); foreach (var point in polyQuadraticBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // ArcSegment else if (pathSegment is ArcSegment) { ArcSegment arcSegment = pathSegment as ArcSegment; WMedia.ArcSegment wSegment = new WMedia.ArcSegment { Size = new WFoundation.Size(arcSegment.Size.Width, arcSegment.Size.Height), RotationAngle = arcSegment.RotationAngle, IsLargeArc = arcSegment.IsLargeArc, SweepDirection = arcSegment.SweepDirection == SweepDirection.Clockwise ? WMedia.SweepDirection.Clockwise : WMedia.SweepDirection.Counterclockwise, Point = arcSegment.Point.ToWindows() }; wPathFigure.Segments.Add(wSegment); } } } wGeometry = wPathGeometry; } return(wGeometry); }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); _path = (Path)GetTemplateChild(pathName); _thumbGrid = (Grid)GetTemplateChild(thumbGridName); _readingBlock = (TextBlock)GetTemplateChild(readingName); PathGeometry geo = new PathGeometry(); _bfigure = new PathFigure(); _bseg = new BezierSegment(); _bfigure.Segments.Add(_bseg); geo.Figures.Add(_bfigure); _path.Data = geo; this.SizeChanged += OnSizeChanged; }