internal static void ComputeOrientationLine(RectangleF rect, float angle, out PointF start, out PointF end)
{
start = PointF.Empty;
end = PointF.Empty;
SizeF tanSize = SizeF.Empty;
// Clamp to 360 degrees
angle = angle % 360;
// We start by breaking the angle up into quadrants
// as per table in comments
if (angle < 90) {
start.X = rect.Location.X;
start.Y = rect.Location.Y;
tanSize.Width = rect.Size.Width;
tanSize.Height = rect.Size.Height;
} else if (angle < 180) {
start.X = rect.Location.X + rect.Size.Width;
start.Y = rect.Location.Y;
tanSize.Width = -rect.Size.Width;
tanSize.Height = rect.Size.Height;
} else if (angle < 270) {
start.X = rect.Location.X + rect.Size.Width;
start.Y = rect.Location.Y + rect.Size.Height;
tanSize.Width = -rect.Size.Width;
tanSize.Height = -rect.Size.Height;
} else {
start.X = rect.Location.X;
start.Y = rect.Location.Y + rect.Size.Height;
tanSize.Width = rect.Size.Width;
tanSize.Height = -rect.Size.Height;
}
float radAngle = angle.ToRadians ();
// Distance formula to get the circle radius - http://en.wikipedia.org/wiki/Distance
float radius = (float)Math.Sqrt (rect.Size.Width * rect.Size.Width + rect.Size.Height * rect.Size.Height);
// get the slope angle
float slopeAngle = (float)Math.Atan2 (tanSize.Height, tanSize.Width);
// Compute the distance
float distance = (float)Math.Cos (slopeAngle - radAngle) * radius;
// Parametric Equation for a circle
// a = angle in radians
// ( cos(a) * d + x, sin(a) * d + y)
end.X = (float)Math.Cos (radAngle) * distance + start.X;
end.Y = (float)Math.Sin (radAngle) * distance + start.Y;
}