import math


def polar_to_cartesian(r, theta, r_ref=0.0, theta_ref=0.0):
    """

    Helper function to convert polar coordinates to Cartesian
    coordinates (relative to a defined reference point).

    :Parameters:

    r: float
        Radial distance of point from origin.
    theta: float
        Angular bearing of point, clockwise from Y axis (in radians)
    r_ref: float (optional)
        Radial distance of reference point from origin
        (if reference point is not the origin).
    theta_ref: float (optional)
        Angular bearing of reference point, clockwise from Y axis
        (in radians)(if reference point is not the origin).

    :Returns:

    (x, y): tuple of 2 floats
        Cartesian coordinates of point

    """
    if float(r_ref) > 0.0:
        x = r * math.sin(theta) - r_ref * math.sin(theta_ref)
        y = r * math.cos(theta) - r_ref * math.cos(theta_ref)
    # Old anticlockwise from the X axis code
    #         x = r * math.cos(theta) - r_ref * math.cos(theta_ref)
    #         y = r * math.sin(theta) - r_ref * math.sin(theta_ref)
    else:
        x = r * math.sin(theta)
        y = r * math.cos(theta)
    # Old anticlockwise from the X axis code
    #         x = r * math.cos(theta)
    #         y = r * math.sin(theta)

    return (x, y)