# Converting from polar coordinates to rectangular coordinates

This is performance critical. I measured and determined that using the sqrt is faster then using the cos method.

I am aware that this code only works for some points, so that is not an issue.

Point is System.Drawing.Point. _offset is also of type Point.

I assumed, and the profiler seemed to confirm, that the try/catch will not slow down the code unless an exception occurs. Please correct me if that is wrong.

/// <summary>
/// Convert from polar coordinates to rectangular coordinates.
/// Only works for points to the left of the origin.
/// </summary>
/// <param name="theta">The angle of the point in radians.</param>
/// <returns>The point in rectangular coordinates.</returns>
internal Point PolarToRectangular(
double theta)
{
try
{
double sin = Math.Sin(theta);

// This is faster then:
// double cos = Math.Cos(theta);
double cos = -Math.Sqrt(1 - (sin * sin));

Int32 x = _offset.X + (Int32)Math.Round(radius * cos);
Int32 y = _offset.Y + (Int32)Math.Round(radius * sin);

return new Point(x, y);
}
catch (OverflowException ex)
{
throw;
}
}


As a completely untested micro-optimisation, I would suspect (Int32)(radius * cosTheta + 0.5) is going to be marginally quicker than (Int32)Math.Round(radius * cosTheta). It does, however, round up on 0.5 instead of rounding down, which may not be what you want.