void DrawArcFromTo (SKCanvas canvas, SKPaint paint, int xc, int yc, int radius, float startAngleInDegrees, float endAngleInDegrees) { if (radius <= 0) return; int x = radius; int y = 0; int cd2 = 0; // convert degrees to radians var startAngleRadians = startAngleInDegrees * Math.PI / 180; var endAngleRadians = endAngleInDegrees * Math.PI / 180; // find x,y coordinates for start and end points var startx = xc + radius * (float)Math.Cos (startAngleRadians); var starty = yc + radius * (float)Math.Sin (startAngleRadians); var startPoint = new SKPoint (startx, starty); var endx = xc + radius * (float)Math.Cos (endAngleRadians); var endy = yc + radius * (float)Math.Sin (endAngleRadians); var endPoint = new SKPoint (endx, endy); // build the path var points = new List<SKPoint> (); // 4 cardinal points var p00 = new SKPoint (xc - radius, yc); var ap00 = Math.Atan2 (p00.Y - yc, p00.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)ap00, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p00); var p01 = new SKPoint (xc + radius, yc); var ap01 = Math.Atan2 (p01.Y - yc, p01.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)ap01, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p01); var p02 = new SKPoint (xc, yc - radius); var ap02 = Math.Atan2 (p02.Y - yc, p02.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)ap02, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p02); var p03 = new SKPoint (xc, yc + radius); var ap03 = Math.Atan2 (p03.Y - yc, p03.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)ap03, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p03); while (x > y) { x--; y++; cd2 -= x - y; if (cd2 < 0) cd2 += x++; // 8 octants - listed clockwise // right hemisphere, starting at the top var p0 = new SKPoint (xc + y, yc - x); var arp0 = Math.Atan2 (p0.Y - yc, p0.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)arp0, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p0); var p1 = new SKPoint (xc + x, yc - y); var arp1 = Math.Atan2 (p1.Y - yc, p1.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)arp1, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p1); var p2 = new SKPoint (xc + x, yc + y); var arp2 = Math.Atan2 (p2.Y - yc, p2.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)arp2, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p2); var p3 = new SKPoint (xc + y, yc + x); var arp3 = Math.Atan2 (p3.Y - yc, p3.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)arp3, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p3); // left hemisphere, continuing around from the bottom var p4 = new SKPoint (xc - y, yc + x); var arp4 = Math.Atan2 (p4.Y - yc, p4.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)arp4, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p4); var p5 = new SKPoint (xc - x, yc + y); var arp5 = Math.Atan2 (p5.Y - yc, p5.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)arp5, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p5); var p6 = new SKPoint (xc - x, yc - y); var arp6 = Math.Atan2 (p6.Y - yc, p6.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)arp6, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p6); var p7 = new SKPoint (xc - y, yc - x); var arp7 = Math.Atan2 (p7.Y - yc, p7.X - xc) * 180 / Math.PI; if (IsAngleBetween ((int)arp7, (int)startAngleInDegrees, (int)endAngleInDegrees)) points.Add (p7); } canvas.DrawPoints (SKPointMode.Points, points.ToArray (), paint); }
void DrawCircle (SKCanvas canvas, SKPaint paint, int xc, int yc, int radius) { if (radius <= 0) return; int x = radius; int y = 0; int cd2 = 0; var points = new List<SKPoint> (); points.Add (new SKPoint (xc - radius, yc)); points.Add (new SKPoint (xc + radius, yc)); points.Add (new SKPoint (xc, yc - radius)); points.Add (new SKPoint (xc, yc + radius)); while (x > y) { cd2 -= (--x) - (++y); if (cd2 < 0) cd2 += x++; // 8 octants - listed clockwise // right hemisphere, starting at the top points.Add (new SKPoint (xc + y, yc - x)); points.Add (new SKPoint (xc + x, yc - y)); points.Add (new SKPoint (xc + x, yc + y)); points.Add (new SKPoint (xc + y, yc + x)); // left hemisphere, continuing around from the bottom points.Add (new SKPoint (xc - y, yc + x)); points.Add (new SKPoint (xc - x, yc + y)); points.Add (new SKPoint (xc - x, yc - y)); points.Add (new SKPoint (xc - y, yc - x)); } canvas.DrawPoints (SKPointMode.Points, points.ToArray (), paint); }