Skip to content

Instantly share code, notes, and snippets.

@jeremysimmons
Created January 10, 2017 18:34
Show Gist options
  • Select an option

  • Save jeremysimmons/0970bc988eea31d74453fe11ebeacf8b to your computer and use it in GitHub Desktop.

Select an option

Save jeremysimmons/0970bc988eea31d74453fe11ebeacf8b to your computer and use it in GitHub Desktop.
void Main()
{
PointF center = new PointF(0f,0f);
for (int i = 1; i <= 12; i++)
{
PointF p = HourToLocation(i, center, 1f);
Console.WriteLine("{0}\t{1}\t{2:F3},{3:F3}", i, HourToAngle(i), Math.Round(p.X,3), Math.Round(p.Y,3));
}
}
int HourToAngle(int hour)
{
if(hour < 1 || hour > 12) throw new ArgumentOutOfRangeException("hour", "Hour must be between 1 and 12");
if (hour <= 3)
return ((3 - hour) * 30);
else
return ((12 - hour) * 30) + 90;
}
PointF HourToLocation(int hour, PointF center, float distance)
{
double degToRad = Math.PI / 180f;
int degrees = HourToAngle(hour);
float x = (float)Math.Cos(degrees * degToRad) * distance;
float y = (float)Math.Sin(degrees * degToRad) * distance;
return new PointF(center.X + x, center.Y + y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment