import math


def rotate_xy(x_orig, y_orig, x_pivot=0, y_pivot=0, angle=0):
    """
    purpose:
        Rotate an xy coordinate around a specified origin
    arguments:
        x_orig: number
            x coordinate of original point
        y_orig: number
            y coordinate of original point
        x_pivot: number
            x coordinate of pivot point
        y_pivot: number
            y coordinate of pivot point
        angle: number
            angle between the original point and the new point using the pivot point as the vertex of the angle
            0-360
            positive numbers for clockwise
            negative numbers for counter-clockwise
    return value: tuple
        x_rotated, y_rotated
        if error: None, None
    """

    try:
        x_orig_delta = x_orig - x_pivot
        y_orig_delta = y_orig - y_pivot
        angle = angle * -1
        # convert angle to radians
        angle = math.radians(angle)
        # get the deltas from the center point to the rotated point
        x_rot_delta = (x_orig_delta * math.cos(angle)) - (y_orig_delta * math.sin(angle))
        y_rot_delta = (x_orig_delta * math.sin(angle)) + (y_orig_delta * math.cos(angle))
        # get the rotated point coords
        x_rot = x_pivot + x_rot_delta
        y_rot = y_pivot + y_rot_delta
        # return a tuple of rotated coords
        return x_rot, y_rot
    except Exception:
        return None, None