# File ../lib/roller/CWRP.rb, line 779
  def rotate(x, y, by)

    # Convert to polar coordinates.
    angle = Math::atan2(y, x)
    magnitude = Math.sqrt(y ** 2 + x ** 2)

    # Rotate (degrees are clockwise and radians are anti-clockwise).
    angle -= by * Math::PI / 180

    # Back to cartesian.
    [Math::cos(angle) * magnitude, Math::sin(angle) * magnitude]
  end