/// <summary> /// Creates the arc segment from parameters of the GDI+ DrawArc function. /// </summary> public static ArcSegment CreateArcSegment(double x, double y, double width, double height, double startAngle, double sweepAngle, out SysPoint startPoint) { // Normalize the angles. double α = startAngle; if (α < 0) α = α + (1 + Math.Floor((Math.Abs(α) / 360))) * 360; else if (α > 360) α = α - Math.Floor(α / 360) * 360; Debug.Assert(α >= 0 && α <= 360); if (Math.Abs(sweepAngle) >= 360) sweepAngle = Math.Sign(sweepAngle) * 360; double β = startAngle + sweepAngle; if (β < 0) β = β + (1 + Math.Floor((Math.Abs(β) / 360))) * 360; else if (β > 360) β = β - Math.Floor(β / 360) * 360; if (α == 0 && β < 0) α = 360; else if (α == 360 && β > 0) α = 0; // Scanling factor. double δx = width / 2; double δy = height / 2; // Center of ellipse. double x0 = x + δx; double y0 = y + δy; double cosα, cosβ, sinα, sinβ; if (width == height) { // Circular arc needs no correction. α = α * Calc.Deg2Rad; β = β * Calc.Deg2Rad; } else { // Elliptic arc needs the angles to be adjusted such that the scaling transformation is compensated. α = α * Calc.Deg2Rad; sinα = Math.Sin(α); if (Math.Abs(sinα) > 1E-10) { if (α < Math.PI) α = Math.PI / 2 - Math.Atan(δy * Math.Cos(α) / (δx * sinα)); else α = 3 * Math.PI / 2 - Math.Atan(δy * Math.Cos(α) / (δx * sinα)); } //α = Calc.πHalf - Math.Atan(δy * Math.Cos(α) / (δx * sinα)); β = β * Calc.Deg2Rad; sinβ = Math.Sin(β); if (Math.Abs(sinβ) > 1E-10) { if (β < Math.PI) β = Math.PI / 2 - Math.Atan(δy * Math.Cos(β) / (δx * sinβ)); else β = 3 * Math.PI / 2 - Math.Atan(δy * Math.Cos(β) / (δx * sinβ)); } //β = Calc.πHalf - Math.Atan(δy * Math.Cos(β) / (δx * sinβ)); } sinα = Math.Sin(α); cosα = Math.Cos(α); sinβ = Math.Sin(β); cosβ = Math.Cos(β); startPoint = new SysPoint(x0 + δx * cosα, y0 + δy * sinα); SysPoint destPoint = new SysPoint(x0 + δx * cosβ, y0 + δy * sinβ); SysSize size = new SysSize(δx, δy); bool isLargeArc = Math.Abs(sweepAngle) >= 180; SweepDirection sweepDirection = sweepAngle > 0 ? SweepDirection.Clockwise : SweepDirection.Counterclockwise; #if !SILVERLIGHT && !NETFX_CORE bool isStroked = true; ArcSegment seg = new ArcSegment(destPoint, size, 0, isLargeArc, sweepDirection, isStroked); #else ArcSegment seg = new ArcSegment(); seg.Point = destPoint; seg.Size = size; seg.RotationAngle = 0; seg.IsLargeArc = isLargeArc; seg.SweepDirection = sweepDirection; // isStroked does not exist in Silverlight 3 #endif return seg; }
private Path getArc(double degreeAngle) { double arcStartPointX = Math.Cos(currentAngle) * Radius + CentrePoint.X; double arcStartPointY = Math.Sin(currentAngle) * Radius + CentrePoint.Y; currentAngle += DegreeToRadian(degreeAngle); double arcEndPointX = Math.Cos(currentAngle) * Radius + CentrePoint.X; double arcEndPointY = Math.Sin(currentAngle) * Radius + CentrePoint.Y; Point arcStartPoint = new Point(arcStartPointX, arcStartPointY); Point arcEndPoint = new Point(arcEndPointX, arcEndPointY); LineSegment line1 = new LineSegment(arcStartPoint, true); LineSegment line2 = new LineSegment(CentrePoint, true); ArcSegment arcSegment = new ArcSegment(); arcSegment.SweepDirection = SweepDirection.Clockwise; arcSegment.Size = new Size(Radius, Radius); arcSegment.RotationAngle = degreeAngle; arcSegment.Point = arcEndPoint; arcSegment.IsLargeArc = degreeAngle > 180.0; PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = CentrePoint; pathFigure.Segments.Add(line1); pathFigure.Segments.Add(arcSegment); pathFigure.Segments.Add(line2); PathFigureCollection pathFigureCollection = new PathFigureCollection(); pathFigureCollection.Add(pathFigure); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures = pathFigureCollection; Path path = new Path(); path.Data = pathGeometry; return(path); }
private void SetPieValues() { var value = GetValue(true); var outherRadius = _outherEllipse.RadiusX; var innerRadius = _innerEllipse.RadiusX; var outherStartPoint = GetPosition(0, _outherEllipse); var outherEndPoint = GetPosition(value, _outherEllipse); var innerStartPoint = GetPosition(0, _innerEllipse); var innerEndPoint = GetPosition(value, _innerEllipse); var lineFromCenterToCircle = new LineSegment(outherStartPoint, false); PathSegment outherSegment; PathSegment innerSegment; if (IsInversed) { outherSegment = new ArcSegment(outherEndPoint, new Size(outherRadius, outherRadius), 45, value < 0.5, SweepDirection.Counterclockwise, false); innerSegment = new ArcSegment(innerStartPoint, new Size(innerRadius, innerRadius), 45, value < 0.5, SweepDirection.Clockwise, false); } else { outherSegment = new ArcSegment(outherEndPoint, new Size(outherRadius, outherRadius), 45, value > 0.5, SweepDirection.Clockwise, false); innerSegment = new ArcSegment(innerStartPoint, new Size(innerRadius, innerRadius), 45, value > 0.5, SweepDirection.Counterclockwise, false); } var lineFromCircleToCenter = new LineSegment(innerEndPoint, false); var pieFigure = new PathFigure(); var pieGeometry = new PathGeometry(); pieGeometry.Figures.Add(pieFigure); pieFigure.StartPoint = innerStartPoint; pieFigure.Segments.Add(lineFromCenterToCircle); pieFigure.Segments.Add(outherSegment); pieFigure.Segments.Add(lineFromCircleToCenter); pieFigure.Segments.Add(innerSegment); _pieEllipse.Clip = pieGeometry; _pieEllipse.RenderTransform = new RotateTransform(StartAngle); }
public Window1() { InitializeComponent(); int gridwidth = 5; Point dot = new Point(); dot.X = 20; dot.Y = 25; Point pointA = new Point(50, 60); Point pointB = new Point(120, 90); Point pointStart = new Point(pointA.X + gridwidth / 2, pointA.Y + 5); Point pointEnd = new Point(pointB.X + gridwidth / 2, pointB.Y + 5); ArcSegment arcSegment = new ArcSegment(pointB, new Size(88, 120), 360, false, SweepDirection.Clockwise, true); PathSegmentCollection pathSegmentCollection = new PathSegmentCollection() { arcSegment }; PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = pointA; pathFigure.Segments = pathSegmentCollection; PathFigureCollection pathFigureCollection = new PathFigureCollection(); pathFigureCollection.Add(pathFigure); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures = pathFigureCollection; Path path = new Path(); path.Data = pathGeometry; path.Stroke = Brushes.Red; path.StrokeThickness = 1; canvas.Children.Add(path); canvas.Background = Brushes.AliceBlue; canvas.UpdateLayout(); }
/// <summary> /// 半圆 /// </summary> /// <param name="startPt"></param> /// <param name="endPt"></param> /// <param name="mainPanel"></param> /// <param name="Static"></param> /// <param name="Sise"></param> /// <param name="brush">绘制颜色</param> /// <param name="width">宽度</param> /// <returns></returns> public Path GetPath(Point startPt, Point endPt, bool Static, int Sise, Brush brush, double width) { Path path = new Path(); PathGeometry pathGeometry = new PathGeometry(); ArcSegment arc = new ArcSegment(startPt, new Size(Sise, Sise), 0, false, Static ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, true); PathFigure figure = new PathFigure(); figure.StartPoint = endPt; figure.Segments.Add(arc); pathGeometry.Figures.Add(figure); path.Data = pathGeometry; path.Stroke = brush; path.StrokeThickness = width; //设置宽度 CanvasMain.Children.Add(path); return(path); }
public void ToString_Should_Return_Path_Markup() { var target = new ArcSegment() { Point = new PointShape(), Size = new PathSize() { Width = 10, Height = 20 }, RotationAngle = 90, IsLargeArc = true, SweepDirection = SweepDirection.Clockwise }; var actual = target.ToString(); Assert.Equal("A10,20 90 1 1 0,0", actual); }
private void MenuItem_Click_2(object sender, RoutedEventArgs e) { //IEnumerable<PathSegment> segments = new List<PathSegment>(); myCanvas.Children.Clear(); IList <PathSegment> segments = new List <PathSegment>(); LineSegment lineSegment = new LineSegment(new Point(100, 100), true); ArcSegment arcSegment = new ArcSegment(new Point(140, 60), new Size(40, 40), 45, false, SweepDirection.Clockwise, true); LineSegment lineSegment1 = new LineSegment(new Point(1440, 60), true); ArcSegment arcSegment1 = new ArcSegment(new Point(1480, 100), new Size(40, 40), 45, false, SweepDirection.Clockwise, true); LineSegment lineSegment2 = new LineSegment(new Point(1480, 300), true); ArcSegment arcSegment2 = new ArcSegment(new Point(1440, 340), new Size(40, 40), 45, false, SweepDirection.Clockwise, true); LineSegment lineSegment3 = new LineSegment(new Point(340, 340), true); ArcSegment arcSegment3 = new ArcSegment(new Point(300, 380), new Size(40, 40), 45, false, SweepDirection.Counterclockwise, true); LineSegment lineSegment4 = new LineSegment(new Point(300, 600), true); ArcSegment arcSegment4 = new ArcSegment(new Point(260, 640), new Size(40, 40), 45, false, SweepDirection.Clockwise, true); LineSegment lineSegment5 = new LineSegment(new Point(140, 640), true); ArcSegment arcSegment5 = new ArcSegment(new Point(100, 600), new Size(40, 40), 45, false, SweepDirection.Clockwise, true); segments.Add(lineSegment); segments.Add(arcSegment); segments.Add(lineSegment1); segments.Add(arcSegment1); segments.Add(lineSegment2); segments.Add(arcSegment2); segments.Add(lineSegment3); segments.Add(arcSegment3); segments.Add(lineSegment4); segments.Add(arcSegment4); segments.Add(lineSegment5); segments.Add(arcSegment5); PathFigure pathFigure = new PathFigure(new Point(100, 600), segments, true); //pathFigure.StartPoint = new Point(100,600); //pathFigure.Segments.Add(lineSegment); //pathFigure.Segments.Add(arcSegment); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); Path path = new Path(); path.Stroke = Brushes.Black; path.StrokeThickness = 1; path.Data = pathGeometry; myCanvas.Children.Add(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); 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 async Task When_Shape_Stretch_UniformToFill() { var topLevelGrid = new Grid(); var grid = new Grid() { Width = 200, Height = 100 }; topLevelGrid.Children.Add(grid); var SUT = new Path() { Stretch = Stretch.Uniform }; grid.Children.Add(SUT); var g = new PathGeometry(); var fig = new PathFigure() { StartPoint = new Point(50, 50) }; var arc = new ArcSegment() { Size = new Size(50, 50), RotationAngle = 45, IsLargeArc = false, SweepDirection = SweepDirection.Clockwise, Point = new Point(70, 70) }; fig.Segments.Add(arc); g.Figures.Add(fig); SUT.Data = g; TestServices.WindowHelper.WindowContent = topLevelGrid; await TestServices.WindowHelper.WaitForIdle(); Assert.IsTrue(MathEx.ApproxEqual(50, SUT.LayoutSlotWithMarginsAndAlignments.X, 1E-3)); Assert.IsTrue(MathEx.ApproxEqual(0, SUT.LayoutSlotWithMarginsAndAlignments.Y, 1E-3)); Assert.IsTrue(MathEx.ApproxEqual(100, SUT.LayoutSlotWithMarginsAndAlignments.Width, 1E-3)); Assert.IsTrue(MathEx.ApproxEqual(100, SUT.LayoutSlotWithMarginsAndAlignments.Height, 1E-3)); }
public void FlattenArcTest(double angle, bool isLargeArc) { var path = new Path { HeightRequest = 200, WidthRequest = 200, Stroke = Brush.Black }; PathFigure figure = new PathFigure(); ArcSegment arcSegment = new ArcSegment { Point = new Point(10, 100), Size = new Size(100, 50), RotationAngle = angle, IsLargeArc = isLargeArc }; figure.Segments.Add(arcSegment); path.Data = new PathGeometry { Figures = new PathFigureCollection { figure } }; List <Point> points = new List <Point>(); GeometryHelper.FlattenArc( points, Point.Zero, arcSegment.Point, arcSegment.Size.Width, arcSegment.Size.Height, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection == SweepDirection.CounterClockwise, 1); Assert.AreNotEqual(0, points.Count); }
/// <summary> /// This method is called whenever the segments /// need to recreate their visual representation. /// </summary> /// <param name="availableSize">The available size which the visual parts can occupy.</param> internal override void ResetSegments(Size availableSize) { this.PrepareReset(availableSize); this.SegmentInfos.Clear(); var currentstartAngle = this.minAngle; var angleSpan = this.maxAngle - this.minAngle; foreach (BarIndicatorSegment segment in this.Segments) { if (segment.Path == null) { Debug.Assert(false, "Missing segment path."); continue; } double lengthRatio = segment.Length / this.TotalSegmentLength; double angle = currentstartAngle + (angleSpan * lengthRatio); PathFigure figure = new PathFigure(); double startAngleInRadians = RadialGaugePanel.ConvertDegreesToRadians(currentstartAngle); figure.StartPoint = RadialGaugePanel.CreateRotatedPoint(startAngleInRadians, this.radius, this.center, this.radiusScale); ArcSegment newArc = new ArcSegment(); newArc.Point = figure.StartPoint; newArc.SweepDirection = SweepDirection.Clockwise; this.SegmentInfos.Add(new SegmentInfo() { PathSegment = newArc, Start = startAngleInRadians, End = RadialGaugePanel.ConvertDegreesToRadians(angle) }); figure.Segments.Add(newArc); PathGeometry pathGeom = new PathGeometry(); pathGeom.Figures.Add(figure); Path path = segment.Path; path.Stroke = segment.Stroke; path.StrokeThickness = segment.Thickness; path.Data = pathGeom; currentstartAngle = angle; } }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); var radius = ActualHeight / 2; // OUTLINE var pen = new Pen(OutlineBrush, OutlineThickness); var center = new Point(ActualWidth / 2, ActualHeight / 2); drawingContext.DrawEllipse(null, pen, center, radius, radius); // var angle = 0.0; var slicePoint = new Point(radius, 0); foreach (var slice in this.slices) { var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure(); pathFigure.StartPoint = center; pathFigure.IsClosed = true; var lineSegment = new LineSegment(slicePoint, true); lineSegment.IsSmoothJoin = true; angle += slice.Value; var arcSegment = new ArcSegment(); var endOfArc = new Point(Math.Cos(angle * Math.PI / 180) * radius + center.X, Math.Sin(angle * Math.PI / 180) * radius + center.Y); arcSegment.IsLargeArc = slice.Value >= 180.0; arcSegment.Point = endOfArc; arcSegment.Size = new Size(radius, radius); arcSegment.SweepDirection = SweepDirection.Clockwise; arcSegment.IsSmoothJoin = true; pathFigure.Segments.Add(lineSegment); pathFigure.Segments.Add(arcSegment); pathGeometry.Figures.Add(pathFigure); var slicePen = new Pen(GetStrokeBySlice(slice), StrokeThickness); drawingContext.DrawGeometry(GetFillBySlice(slice), slicePen, pathGeometry); slicePoint = endOfArc; } }
private void DefineGeometry() { var points = PointCollection; _figure.Segments.Clear(); if (points.Any()) { // start point _figure.StartPoint = points[0]; if (points.Count > 1) { // points between for (int i = 1; i < (points.Count - 1); i++) { // adjust radius if points are too close var v1 = (Point)points[i] - points[i - 1]; var v2 = (Point)points[i + 1] - points[i]; var radius = (points[i].Radius ?? Radius) ?? 0; radius = Math.Min(Math.Min(v1.Length, v2.Length) / 2, radius); // draw the line, and stop before the next point double len = v1.Length; v1.Normalize(); v1 *= (len - radius); var line = new LineSegment((Point)points[i - 1] + v1, true); _figure.Segments.Add(line); // draw the arc to the next point v2.Normalize(); v2 *= radius; var direction = (Vector.AngleBetween(v1, v2) > 0) ? SweepDirection.Clockwise : SweepDirection.Counterclockwise; var arc = new ArcSegment((Point)points[i] + v2, new Size(radius, radius), 0, false, direction, true); _figure.Segments.Add(arc); } // last point _figure.Segments.Add(new LineSegment(points[points.Count - 1], true)); } } }
public static Shape SetArc(Brush brush, Point firstDot, Point secondDot, Point thirdDot, Canvas canvas) { Path myPath = new Path(); myPath.Stroke = brush; myPath.StrokeThickness = OptionDrawLine.strokeThickness; myPath.MinHeight = 10; PathGeometry pathGeometry = new PathGeometry(); PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = firstDot; ArcSegment arc = new ArcSegment(); arc.Point = secondDot; double dist = FindLength(firstDot, secondDot); double x0 = thirdDot.X, y0 = thirdDot.Y; double x1 = firstDot.X, y1 = firstDot.Y; double x2 = secondDot.X, y2 = secondDot.Y; double xc = -0.5 * (y0 * (x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2) + y1 * (x2 * x2 + y2 * y2 - x0 * x0 - y0 * y0) + y2 * (x0 * x0 + y0 * y0 - x1 * x1 - y1 * y1)) / (x0 * (y1 - y2) + x1 * (y2 - y0) + x2 * (y0 - y1)); double yc = 0.5 * (x0 * (x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2) + x1 * (x2 * x2 + y2 * y2 - x0 * x0 - y0 * y0) + x2 * (x0 * x0 + y0 * y0 - x1 * x1 - y1 * y1)) / (x0 * (y1 - y2) + x1 * (y2 - y0) + x2 * (y0 - y1)); Vector vect1 = new Vector(x1 - xc, y1 - yc); Vector vect2 = new Vector(x2 - xc, y2 - yc); double atan = Math.Atan2(vect1.X * vect2.Y - vect1.Y * vect2.X, vect1.X * vect2.X + vect1.Y * vect2.Y); double radius = FindLength(firstDot, new Point(xc, yc)); double height = -((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) / dist; if (height < 0) { arc.SweepDirection = SweepDirection.Clockwise; atan = -atan; } if (atan > 0) { arc.IsLargeArc = true; } arc.Size = new Size(radius, radius); pathFigure.Segments.Add(arc); pathGeometry.Figures.Add(pathFigure); myPath.Data = pathGeometry; canvas.Children.Add(myPath); return(myPath); }
private void CreatePiePathAndGeometries() { ClearPathDictionary(); if (Data != null) { var total = Data.GetTotal(); if (total > 0) { var angle = -Math.PI / 2; foreach (var ps in Data) { //PieSegment ps = Data[1]; Geometry geometry; var path = new Path(); if (ps.Value == total) { geometry = new EllipseGeometry(new Point(Width / 2, Height / 2), Width / 2, Height / 2); } else { geometry = new PathGeometry(); var x = Math.Cos(angle) * Width / 2 + Width / 2; var y = Math.Sin(angle) * Height / 2 + Height / 2; var lingeSeg = new LineSegment(new Point(x, y), true); var angleShare = ps.Value / total * 360; angle += DegreeToRadian(angleShare); x = Math.Cos(angle) * Width / 2 + Width / 2; y = Math.Sin(angle) * Height / 2 + Height / 2; var arcSeg = new ArcSegment(new Point(x, y), new Size(Width / 2, Height / 2), angleShare, angleShare > 180, SweepDirection.Clockwise, false); var lingeSeg2 = new LineSegment(new Point(Width / 2, Height / 2), true); var fig = new PathFigure(new Point(Width / 2, Height / 2), new PathSegment[] { lingeSeg, arcSeg, lingeSeg2 }, false); ((PathGeometry)geometry).Figures.Add(fig); } path.Fill = ps.SolidBrush; path.Data = geometry; AddPathToDictionary(path, ps); drawingCanvas.Children.Add(path); } } } }
public PieSlice() { 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(); }
void CheckBounds() { if (currentArc.ContainsPoint(transform.position, 0.05f)) { //onGround = true; } else { if (currentArc.nextArc != null && currentArc.nextArc.ContainsPoint(transform.position, 0.05f)) { TrackManager.instance.IncrementArc(); currentArc = TrackManager.instance.currentArc; } else { onGround = false; } } }
private Path DrawPie(double _angle) { //半径 double radius = 50.0; //角度 double angle = _angle; Path path = new Path { Fill = (Brush)(new BrushConverter().ConvertFromString("#FFD6D0FF")), Stroke = (Brush)(new BrushConverter().ConvertFromString("#FFD6D0FF")), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(100) }; PathGeometry pathGeometry = new PathGeometry(); PathFigure pathFigure = new PathFigure { StartPoint = new Point(0, 0), IsClosed = true }; // Starting Point LineSegment lineSegment = new LineSegment(new Point(radius, 0), true); // Arc ArcSegment arcSegment = new ArcSegment { IsLargeArc = angle >= 180.0, Point = new Point(Math.Cos(angle * Math.PI / 180) * radius, Math.Sin(angle * Math.PI / 180) * radius), Size = new Size(radius, radius), SweepDirection = SweepDirection.Clockwise }; pathFigure.Segments.Add(lineSegment); pathFigure.Segments.Add(arcSegment); pathGeometry.Figures.Add(pathFigure); path.Data = pathGeometry; return(path); }
private static void OnScaleChanged(DependencyObject d) { RadialGauge radialGauge = (RadialGauge)d; radialGauge.UpdateNormalizedAngles(); var scale = radialGauge.GetTemplateChild(ScalePartName) as Path; if (scale != null) { if (radialGauge.NormalizedMaxAngle - radialGauge.NormalizedMinAngle == 360) { // Draw full circle. var eg = new EllipseGeometry(); eg.Center = new Point(100, 100); eg.RadiusX = 100 - radialGauge.ScalePadding - (radialGauge.ScaleWidth / 2); eg.RadiusY = eg.RadiusX; scale.Data = eg; } else { // Draw arc. var pg = new PathGeometry(); var pf = new PathFigure(); pf.IsClosed = false; var middleOfScale = 100 - radialGauge.ScalePadding - (radialGauge.ScaleWidth / 2); pf.StartPoint = radialGauge.ScalePoint(radialGauge.NormalizedMinAngle, middleOfScale); var seg = new ArcSegment(); seg.SweepDirection = SweepDirection.Clockwise; seg.IsLargeArc = radialGauge.NormalizedMaxAngle > (radialGauge.NormalizedMinAngle + 180); seg.Size = new Size(middleOfScale, middleOfScale); seg.Point = radialGauge.ScalePoint(radialGauge.NormalizedMaxAngle, middleOfScale); pf.Segments.Add(seg); pg.Figures.Add(pf); scale.Data = pg; } if (!DesignTimeHelpers.IsRunningInLegacyDesignerMode) { OnFaceChanged(radialGauge); } } }
public void MakeData() { ArcSegment asm = new ArcSegment(EndPoint, new Size(Radius, Radius), 0, LargeArc, SweepDirection.Clockwise, true); PathSegmentCollection psc = new PathSegmentCollection(); psc.Add(asm); PathFigure pf = new PathFigure(); pf.StartPoint = StartPoint; pf.Segments = psc; PathFigureCollection pfc = new PathFigureCollection(); pfc.Add(pf); PathGeometry pg = new PathGeometry(); pg.Figures = pfc; GeometryData = pg; }
/// <summary> /// Default constructor. /// </summary> public SurfaceWindow1() { InitializeComponent(); Path myShape = new Path(); myShape.StrokeThickness = 3.0; myShape.Fill = System.Windows.Media.Brushes.Wheat; myShape.Stroke = System.Windows.Media.Brushes.BlueViolet; PathGeometry myGeometry = new PathGeometry(); PathFigure figure = new PathFigure(); //Figure draws the segments upside down (this the coordinate system in negatives to draw objects) Double width = 200; Double height = 100; figure.SetValue(PathFigure.StartPointProperty, new Point(height, 0)); ArcSegment arc = new ArcSegment(new Point(height, height), new Size(height / 2, height / 2), 0.0, true, SweepDirection.Counterclockwise, true); //Note: LineSegments take end point as the constructor, Their Start point will be the end point of previous segment(the order you added into path figure(Source API)) LineSegment arcVertical1 = new LineSegment(new Point(height, height - 25), true); LineSegment horizontal1 = new LineSegment(new Point(height + 275, height - 25), true); LineSegment vertical = new LineSegment(new Point(height + 275, 25), true); LineSegment horizontal2 = new LineSegment(new Point(height, 25), true); LineSegment arcVertical2 = new LineSegment(new Point(height, 0), true); figure.Segments.Add(arc); figure.Segments.Add(arcVertical1); figure.Segments.Add(horizontal1); figure.Segments.Add(vertical); figure.Segments.Add(horizontal2); figure.Segments.Add(arcVertical2); myGeometry.Figures.Add(figure); myShape.Data = myGeometry; myCanvas.Children.Add(myShape); //****************************** Register for Stroke change events************************* // This is how we can get the currently being drawn stroke information inkCanvas.Strokes.StrokesChanged += new StrokeCollectionChangedEventHandler(canvasStrokesChanged); // Add handlers for window availability events AddWindowAvailabilityHandlers(); }
public CamberLoadingRingCell() : base() { this.line1 = new LineSegment(); this.line2 = new LineSegment(); this.arc1 = new ArcSegment(); this.arc2 = new ArcSegment(); this.figure = new PathFigure() { IsClosed = true, IsFilled = true, Segments = new PathSegmentCollection() { line1, arc1, line2, arc2 } }; this.OnFactorChanged(this.CellRadian, this.Direction, this.InnerRadius, this.OuterRadius); this.geometry = new PathGeometry(new[] { this.figure }); }
private void UpdatePath(double startAngle, double endAngle) { var radius = this.Radius - this.StrokeThickness / 2; if (_isUpdating || this.ActualWidth == 0 || radius <= 0) { return; } var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure { StartPoint = new Point(radius, radius), 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(); }
void CreatePiePathAndGeometries() { ClearPathDictionary(); drawingCanvas.Children.Clear(); drawingCanvas.Children.Add(piePopup); if (Data != null) { double total = Data.GetTotal(); if (total > 0) { double angle = -Math.PI / 2; foreach (PieSegment ps in Data) { Geometry geometry; Path path = new Path(); if (ps.Value == total) { geometry = new EllipseGeometry(new Point(this.Width / 2, this.Height / 2), this.Width / 2, this.Height / 2); } else { geometry = new PathGeometry(); double x = Math.Cos(angle) * Width / 2 + Width / 2; double y = Math.Sin(angle) * Height / 2 + Height / 2; LineSegment lingeSeg = new LineSegment(new Point(x, y), true); double angleShare = (ps.Value / total) * 360; angle += DegreeToRadian(angleShare); x = Math.Cos(angle) * Width / 2 + Width / 2; y = Math.Sin(angle) * Height / 2 + Height / 2; ArcSegment arcSeg = new ArcSegment(new Point(x, y), new Size(Width / 2, Height / 2), angleShare, angleShare > 180, SweepDirection.Clockwise, false); LineSegment lingeSeg2 = new LineSegment(new Point(Width / 2, Height / 2), true); PathFigure fig = new PathFigure(new Point(Width / 2, Height / 2), new PathSegment[] { lingeSeg, arcSeg, lingeSeg2 }, false); ((PathGeometry)geometry).Figures.Add(fig); } path.Fill = ps.GradientBrush; path.Data = geometry; AddPathToDictionary(path, ps); drawingCanvas.Children.Add(path); } } } }
/// <summary> /// Parses a PolyBezierSegment element. /// </summary> ArcSegment ParseArcSegment() { Debug.Assert(this.reader.Name == "ArcSegment"); ArcSegment seg = new ArcSegment(); seg.IsStroked = true; while (MoveToNextAttribute()) { switch (this.reader.Name) { case "Point": seg.Point = Point.Parse(this.reader.Value); break; case "Size": seg.Size = Size.Parse(this.reader.Value); break; case "RotationAngle": seg.RotationAngle = ParseDouble(this.reader.Value); break; case "IsLargeArc": seg.IsLargeArc = ParseBool(this.reader.Value); break; case "SweepDirection": seg.SweepDirection = ParseEnum <SweepDirection>(this.reader.Value); break; case "IsStroked": seg.IsStroked = ParseBool(this.reader.Value); break; default: UnexpectedAttribute(this.reader.Name); break; } } MoveBeyondThisElement(); return(seg); }
void _chart_OnDrawPie(object sender, Chart.DrawEventArgs <Events.PieDrawingData> e) { double size = ((e.Data.X > e.Data.Y) ? e.Data.Y * 2 : e.Data.X * 2); double halfSize = size / 2; WPPoint previousPoint = new WPPoint(halfSize, 0); for (int i = 0; i < e.Data.Percentages.Length; i++) { double value = e.Data.Percentages[i]; double coordinateX = halfSize * Math.Sin(value); double coordinateY = halfSize * Math.Cos(value); Path path = new Path(); PathFigure pathFigure = new PathFigure(); pathFigure.IsClosed = true; pathFigure.StartPoint = new WPPoint(halfSize, halfSize); LineSegment lineSegment = new LineSegment(); lineSegment.Point = previousPoint; pathFigure.Segments.Add(lineSegment); previousPoint = new WPPoint(coordinateX + halfSize, coordinateY + halfSize); ArcSegment arcSegment = new ArcSegment(); arcSegment.Size = new WPSize(halfSize, halfSize); arcSegment.Point = previousPoint; arcSegment.RotationAngle = 0; arcSegment.IsLargeArc = value > 180 ? true : false; arcSegment.SweepDirection = SweepDirection.Clockwise; pathFigure.Segments.Add(arcSegment); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures = new PathFigureCollection(); pathGeometry.Figures.Add(pathFigure); path.Data = pathGeometry; path.Fill = new SolidColorBrush(Colors[i]); this.Children.Add(path); } }
private void MenuItem_Click(object sender, RoutedEventArgs e) { myCanvas.Children.Clear(); /* * Rect rect = new Rect(100,100,1500,300); * RectangleGeometry rectangel = new RectangleGeometry(rect, 60, 60); * Path path = new Path(); * path.StrokeThickness = 1; * path.Stroke = Brushes.Black; * path.Data = rectangel; * myCanvas.Children.Add(path); */ IList <PathSegment> segments = new List <PathSegment>(); LineSegment lineSegment = new LineSegment(new Point(160, 100), true); ArcSegment arcSegment = new ArcSegment(new Point(100, 160), new Size(60, 60), 45, false, SweepDirection.Counterclockwise, true); LineSegment lineSegment1 = new LineSegment(new Point(100, 340), true); ArcSegment arcSegment1 = new ArcSegment(new Point(160, 400), new Size(60, 60), 45, false, SweepDirection.Counterclockwise, true); LineSegment lineSegment2 = new LineSegment(new Point(1540, 400), true); ArcSegment arcSegment2 = new ArcSegment(new Point(1600, 340), new Size(60, 60), 45, false, SweepDirection.Counterclockwise, true); LineSegment lineSegment3 = new LineSegment(new Point(1600, 160), true); ArcSegment arcSegment3 = new ArcSegment(new Point(1540, 100), new Size(60, 60), 45, false, SweepDirection.Counterclockwise, true); segments.Add(lineSegment); segments.Add(arcSegment); segments.Add(lineSegment1); segments.Add(arcSegment1); segments.Add(lineSegment2); segments.Add(arcSegment2); segments.Add(lineSegment3); segments.Add(arcSegment3); PathFigure pathFigure = new PathFigure(new Point(1540, 100), segments, true); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); Path path = new Path(); path.Stroke = Brushes.Black; path.StrokeThickness = 2; path.Data = pathGeometry; myCanvas.Children.Add(path); }
/// <summary> /// Draws an arc with the passed parameters /// Take care with the usage, because arcs are costly to draw /// </summary> /// <param name="renderTarget"></param> /// <param name="brush"></param> /// <param name="center"></param> /// <param name="radius"></param> /// <param name="startAngle"></param> /// <param name="sweepAngle"></param> /// <param name="strokeWidth"></param> public static void Draw(RenderTarget renderTarget, Brush brush, Vector2 center, float radius, float startAngle, float sweepAngle, float strokeWidth = 1f) { if (sweepAngle <= 0f) { throw new ArgumentException("Sweep angle is 0 or below"); } if (renderTarget.IsDisposed) { throw new ObjectDisposedException(nameof(renderTarget)); } radius = Math.Max(radius, 1f); ArcSegment arcSegment = new ArcSegment(); arcSegment.ArcSize = sweepAngle > 180f ? ArcSize.Large : ArcSize.Small; arcSegment.Point = PointOnCircle(center, radius, startAngle - (sweepAngle >= 360f ? 359.9f : sweepAngle)); arcSegment.RotationAngle = 0f; arcSegment.Size = new Size2F(radius, radius); arcSegment.SweepDirection = SweepDirection.CounterClockwise; using (PathGeometry path = new PathGeometry(Factory)) using (GeometrySink sink = path.Open()) { sink.BeginFigure(PointOnCircle(center, radius, startAngle), FigureBegin.Filled); sink.AddArc(arcSegment); sink.EndFigure(FigureEnd.Open); sink.Close(); renderTarget.DrawGeometry(path, brush, strokeWidth); } renderTarget.AntialiasMode = AntialiasMode.PerPrimitive; }
/// <summary> /// Calculates the midpoint of the arc passed as a parameter, as well as whether the arc is small. /// </summary> /// <param name="center">The center of the pie chart.</param> /// <param name="startPoint">The start point of the arc segment.</param> /// <param name="arcSegment">The arc of the pie wedge itself.</param> /// <param name="arcMidpoint">he midpoint of the arc in the pie wedge.</param> /// <param name="isArcSmall">True if the arc is small, false otherwise.</param> private static void CalculateArcInfo(Point center, Point startPoint, ArcSegment arcSegment, out Point arcMidpoint, out bool isArcSmall) { // Note: we assume a valid arcSegment with equal radii. Debug.Assert(arcSegment != null); Debug.Assert(arcSegment.Size.Width == arcSegment.Size.Height); Point endPoint = arcSegment.Point; Point chordMidpoint = new Point(0.5 * (startPoint.X + endPoint.X), 0.5 * (startPoint.Y + endPoint.Y)); Vector chordDirection = endPoint - startPoint; double chordLength = chordDirection.Length; double radius = arcSegment.Size.Width; isArcSmall = chordLength < DistanceSmallArc; // If the chord length is less than the distance tolerance, just use the chord midpoint // or the point on the opposite side of the circle as appropriate. if (chordLength < DistanceTolerance) { arcMidpoint = arcSegment.IsLargeArc ? center - (chordMidpoint - center) : chordMidpoint; } else { chordDirection /= chordLength; Vector radialDirection = new Vector(-chordDirection.Y, chordDirection.X); double halfChordLength = 0.5 * chordLength; double radialOffset; if (radius >= halfChordLength) { double sectorRadius = Math.Sqrt(radius * radius - halfChordLength * halfChordLength); radialOffset = -radius + (arcSegment.IsLargeArc ? -sectorRadius : sectorRadius); } else { radialOffset = -halfChordLength; } if (arcSegment.SweepDirection == SweepDirection.Counterclockwise) { radialOffset = -radialOffset; } arcMidpoint = chordMidpoint + radialOffset * radialDirection; } }
/// <summary> /// ドーナツ形、アーチ形のPathGeometry作成 /// </summary> /// <param name="center">中心座標</param> /// <param name="width">幅</param> /// <param name="distance">中心からの距離</param> /// <param name="startDeg">開始角度、0以上360未満</param> /// <param name="stopDeg">終了角度、0以上360未満</param> /// <param name="direction">回転方向、clockwiseが時計回り</param> /// <returns></returns> private PathGeometry DonutGeometry(Point center, double width, double distance, double startDeg, double stopDeg, SweepDirection direction) { //外側の円弧終始点 Point outSideStart = MakePoint(startDeg, center, distance); Point outSideStop = MakePoint(stopDeg, center, distance); //内側の円弧終始点は角度と回転方向が外側とは逆になる Point inSideStart = MakePoint(stopDeg, center, distance - width); Point inSideStop = MakePoint(startDeg, center, distance - width); //開始角度から終了角度までが180度を超えているかの判定 //超えていたらArcSegmentのIsLargeArcをtrue、なければfalseで作成 double diffDegrees = (direction == SweepDirection.Clockwise) ? stopDeg - startDeg : startDeg - stopDeg; if (diffDegrees < 0) { diffDegrees += 360.0; } bool isLarge = (diffDegrees > 180) ? true : false; //arcSegment作成 var outSideArc = new ArcSegment(outSideStop, new Size(distance, distance), 0, isLarge, direction, true); //内側のarcSegmentは回転方向を逆で作成 var inDirection = (direction == SweepDirection.Clockwise) ? SweepDirection.Counterclockwise : SweepDirection.Clockwise; var inSideArc = new ArcSegment(inSideStop, new Size(distance - width, distance - width), 0, isLarge, inDirection, true); //PathFigure作成、外側から内側で作成している //2つのarcSegmentは、2本の直線(LineSegment)で繋げる var fig = new PathFigure(); fig.StartPoint = outSideStart; fig.Segments.Add(outSideArc); fig.Segments.Add(new LineSegment(inSideStart, true)); //外側終点から内側始点への直線 fig.Segments.Add(inSideArc); fig.Segments.Add(new LineSegment(outSideStart, true)); //内側終点から外側始点への直線 fig.IsClosed = true; //Pathを閉じる必須 var pg = new PathGeometry(); pg.Figures.Add(fig); return(pg); }
/// <summary> /// Converts an ArcSegment into a PolyLineSegment because I currently have no muse to calculate /// the correct Bézier curves. /// </summary> public static PolyLineSegment FlattenSegment( Point startPoint, ArcSegment seg) { var geo = new PathGeometry(); var fig = new PathFigure(); geo.Figures.Add(fig); fig.StartPoint = new Point(startPoint.X, startPoint.Y); var aseg = new ArcSegment(new Point(seg.Point.X, seg.Point.Y), new Size(seg.Size.Width, seg.Size.Height), seg.RotationAngle, seg.IsLargeArc, seg.SweepDirection, seg.IsStroked); fig.Segments.Add(aseg); geo = geo.GetFlattenedPathGeometry(); fig = geo.Figures[0]; //PolyLineSegment lineSeg = (PolyLineSegment)fig.Segments[0]; var resultSeg = new PolyLineSegment(); int count = fig.Segments.Count; for (int idx = 0; idx < count; idx++) { var pathSeg = fig.Segments[idx]; if (pathSeg is PolyLineSegment) { var plseg = (PolyLineSegment)pathSeg; foreach (var point in plseg.Points) { resultSeg.Points.Add(new Point(point.X, point.Y)); } } else if (pathSeg is LineSegment) { var lseg = (LineSegment)pathSeg; resultSeg.Points.Add(new Point(lseg.Point.X, lseg.Point.Y)); } else { Debugger.Break(); } } return(resultSeg); }
/// <summary> /// Adds an elliptical arc to the current figure. The arc is specified WPF like. /// </summary> public void AddArc(XPoint point1, XPoint point2, XSize size, double rotationAngle, bool isLargeArg, XSweepDirection sweepDirection) { #if CORE _corePath.AddArc(point1, point2, size, rotationAngle, isLargeArg, sweepDirection); #endif #if GDI DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddArc"); #endif #if WPF PathFigure figure = CurrentPathFigure; if (figure.Segments.Count == 0) figure.StartPoint = point1.ToPoint(); else { // figure.Segments.Add(new LineSegment(point1.ToPoint(), true)); #if !SILVERLIGHT LineSegment lineSegment = new LineSegment(point1.ToPoint(), true); #else LineSegment lineSegment = new LineSegment(); lineSegment.Point = point1.ToPoint(); #endif figure.Segments.Add(lineSegment); } // figure.Segments.Add(new ArcSegment(point2.ToPoint(), size.ToSize(), rotationAngle, isLargeArg, sweepDirection, true)); #if !SILVERLIGHT ArcSegment arcSegment = new ArcSegment(point2.ToPoint(), size.ToSize(), rotationAngle, isLargeArg, (SweepDirection)sweepDirection, true); #else ArcSegment arcSegment = new ArcSegment(); arcSegment.Point = point2.ToPoint(); arcSegment.Size = size.ToSize(); arcSegment.RotationAngle = rotationAngle; arcSegment.IsLargeArc = isLargeArg; arcSegment.SweepDirection = (SweepDirection)sweepDirection; #endif figure.Segments.Add(arcSegment); #endif }
/// <summary> /// Adds an ellipse to the current path. /// </summary> public void AddEllipse(double x, double y, double width, double height) { #if CORE double w = width / 2; double h = height / 2; double xc = x + w; double yc = y + h; _corePath.MoveTo(x + w, y); _corePath.QuadrantArcTo(xc, yc, w, h, 1, true); _corePath.QuadrantArcTo(xc, yc, w, h, 4, true); _corePath.QuadrantArcTo(xc, yc, w, h, 3, true); _corePath.QuadrantArcTo(xc, yc, w, h, 2, true); _corePath.CloseSubpath(); #endif #if GDI try { Lock.EnterGdiPlus(); _gdipPath.AddEllipse((float)x, (float)y, (float)width, (float)height); } finally { Lock.ExitGdiPlus(); } #endif #if WPF || NETFX_CORE #if !SILVERLIGHT && !NETFX_CORE _pathGeometry.AddGeometry(new EllipseGeometry(new Rect(x, y, width, height))); #else var figure = new PathFigure(); figure.StartPoint = new SysPoint(x, y + height / 2); var segment = new ArcSegment { Point = new SysPoint(x + width, y + height / 2), Size = new SysSize(width / 2, height / 2), IsLargeArc = true, RotationAngle = 180, SweepDirection = SweepDirection.Clockwise, }; figure.Segments.Add(segment); segment = new ArcSegment { Point = figure.StartPoint, Size = new SysSize(width / 2, height / 2), IsLargeArc = true, RotationAngle = 180, SweepDirection = SweepDirection.Clockwise, }; figure.Segments.Add(segment); _pathGeometry.Figures.Add(figure); #endif // StartFigure() isn't needed because AddGeometry() implicitly starts a new figure, // but CloseFigure() is needed for the next adding not to continue this figure. CloseFigure(); #endif }
private void UpdatePath(double startAngle, double endAngle) { var radius = this.Radius - this.StrokeThickness / 2; if (_isUpdating || this.ActualWidth == 0 || radius <= 0) { return; } var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure { StartPoint = new Point(radius, radius), 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 void Arc(Canvas surface, double left, double top, double right, double bottom, double startArcX, double startArcY, double endArcX, double endArcY) { var arc = new Path(); var figure = new PathFigure(); var segments = new PathSegmentCollection(); var center = new Point(left + ((right - left) / 2), top + ((bottom - top) / 2)); double degrees = Math.Atan2(startArcY - center.Y, startArcX - center.X) - Math.Atan2(endArcY - center.Y, endArcX - center.X); degrees *= 57.2957795; // Convert from radians to degrees bool isLargeArc = Math.Abs(degrees) > 180; arc.Data = new PathGeometry(); figure.StartPoint = new Point(LtoDX(startArcX), LtoDY(startArcY)); var segment = new ArcSegment { Point = new Point( LtoDX(endArcX), LtoDY(endArcY)), Size = new Size( (LtoDX(right) - LtoDX(left)) / 2, (LtoDY(bottom) - LtoDY(top)) / 2), RotationAngle = 0, IsLargeArc = isLargeArc, SweepDirection = SweepDirection.Counterclockwise }; segments.Add(segment); figure.Segments = segments; ((PathGeometry)arc.Data).Figures.Add(figure); ApplyStyle(arc, false); surface.Children.Add(arc); }
public void AddArc(ArcSegment arc) { }
public void AddArc(PointF endPoint, SizeF size, float rotationAngle) { var segment = new ArcSegment(); segment.ArcSize = ArcSize.Small; segment.EndPoint = endPoint.InternalPointF; segment.RotationAngle = rotationAngle; segment.Size = size.InternalSize; segment.SweepDirection = SweepDirection.Clockwise; m_geometrySink.AddArc(segment); }
/// <summary> /// Returns new ArcSegment by easing startValue to endValue using a time percentage 0 -> 1. /// </summary> /// <example>XAML: Data="M 10,100 A 100,50 45 1 0 200,100"</example> /// <seealso cref="http://msdn.microsoft.com/en-us/library/system.windows.media.arcsegment.aspx"/> public static ArcSegment EaseValue(ArcSegment startValue, ArcSegment endValue, double percent) { return new ArcSegment { IsLargeArc = endValue.IsLargeArc, Point = EaseValue(startValue.Point, endValue.Point, percent), RotationAngle = EaseValue(startValue.RotationAngle, endValue.RotationAngle, percent), Size = EaseValue(startValue.Size, endValue.Size, percent), SweepDirection = endValue.SweepDirection, }; }
public void Pie(Canvas surface, double left, double top, double right, double bottom, double radial1X, double radial1Y, double radial2X, double radial2Y) { var pie = new Path(); var figure = new PathFigure(); var segments = new PathSegmentCollection(); var center = new Point(left + ((right - left) / 2), top + ((bottom - top) / 2)); var degrees = Math.Atan2(radial1Y - center.Y, radial1X - center.X) - Math.Atan2(radial2Y - center.Y, radial2X - center.X); degrees *= 57.2957795; // Convert from radians to degrees bool isLargeArc = Math.Abs(degrees) > 180; pie.Data = new PathGeometry(); figure.IsClosed = true; figure.StartPoint = new Point(LtoDX(radial1X), LtoDY(radial1Y)); var segment = new ArcSegment { Point = new Point(LtoDX(radial1X), LtoDY(radial1Y)), Size = new Size((LtoDX(right) - LtoDX(left)) / 2, (LtoDY(bottom) - LtoDY(top)) / 2), RotationAngle = 0, IsLargeArc = isLargeArc, SweepDirection = SweepDirection.Counterclockwise, }; segments.Add(segment); segments.Add( new LineSegment { Point = center } ); figure.Segments = segments; ((PathGeometry)pie.Data).Figures.Add(figure); ApplyStyle(pie, true); surface.Children.Add(pie); }
public void AddArc(ArcSegment arc) { _buffer.AppendFormat("A {0},{1} {2},{3} ", arc.Size.Width, arc.Size.Height, arc.RotationAngle, (int)arc.ArcSize, (int)arc.SweepDirection, arc.Point.X, arc.Point.Y); }
void GeometrySink.AddArc(ArcSegment arc) { throw new NotSupportedException(); }
public PathGeometry CloneDeep(PathGeometry pathGeometry) { var newPathGeometry = new PathGeometry(); foreach (var figure in pathGeometry.Figures) { var newFigure = new PathFigure(); newFigure.StartPoint = figure.StartPoint; // Even figures have to be deep cloned. Assigning them directly will result in // an InvalidOperationException being thrown with the message "Element is already the child of another element." foreach (var segment in figure.Segments) { // I only impemented cloning the abstract PathSegments to one implementation, // the PolyLineSegment class. If your paths use other kinds of segments, you'll need // to implement that kind of coding yourself. 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 segmentAsLineSegment = segment as LineSegment; if (segmentAsLineSegment != null) { var newSegment = new LineSegment(); newSegment.Point = segmentAsLineSegment.Point; newFigure.Segments.Add(newSegment); } var segmentAsArcSegment = segment as ArcSegment; if (segmentAsArcSegment != null) { var newSegment = new ArcSegment(); newSegment.Point = segmentAsArcSegment.Point; newSegment.SweepDirection = segmentAsArcSegment.SweepDirection; newSegment.RotationAngle = segmentAsArcSegment.RotationAngle; newSegment.IsLargeArc = segmentAsArcSegment.IsLargeArc; newSegment.Size = segmentAsArcSegment.Size; newFigure.Segments.Add(newSegment); } } newPathGeometry.Figures.Add(newFigure); } return newPathGeometry; }
public void AddArc(ArcSegment arc) { AddArc_(ref arc); }