Skip to content

Instantly share code, notes, and snippets.

@bradmartin333
Last active August 5, 2021 14:27
Show Gist options
  • Save bradmartin333/c3fd5b37f504b31972d71b2f381dbc44 to your computer and use it in GitHub Desktop.
Save bradmartin333/c3fd5b37f504b31972d71b2f381dbc44 to your computer and use it in GitHub Desktop.
Generate linear scan coordinates for a circular area
using System;
using System.Collections.Generic;
using System.Drawing;
namespace PiePrep
{
class Program
{
static void Main(string[] args)
{
Console.Write("\nEnter X center (mm): ");
string x = Console.ReadLine();
Console.Write("\nEnter Y center (mm): ");
string y = Console.ReadLine();
PointF center = new PointF(float.Parse(x), float.Parse(y));
Console.Write("\nEnter radius (mm): ");
float radius = float.Parse(Console.ReadLine());
Console.Write("\nEnter number of slices: ");
float slices = float.Parse(Console.ReadLine()) * 2;
List<PointF> points = new List<PointF>();
float dtheta = (float)(2 * Math.PI / slices);
float theta = 0;
for (int i = 0; i < slices; i++)
{
float xs = (float)(center.X + radius * Math.Cos(theta));
float ys = (float)(center.Y + radius * Math.Sin(theta));
points.Add(new PointF(xs, ys));
theta += dtheta;
}
for (int i = 0; i < points.Count; i+=2)
{
Console.WriteLine(string.Format("\nScan {0}: [{1}, {2}] --> [{3}, {4}]", i / 2 + 1,
points[i].X.ToString("0.000"), points[i].Y.ToString("0.000"),
points[i + 1].X.ToString("0.000"), points[i + 1].Y.ToString("0.000")));
}
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment