def pyelastica_rod(
    x,
    r,
    color="rgb<0.45,0.39,1>",
    transmit=0.0,
    interpolation="linear_spline",
    deform=None,
    tab="    ",
):
    """pyelastica_rod POVray script generator

    Generates povray sphere_sweep object in string.
    The rod is given with the element radius (r) and joint positions (x)

    Parameters
    ----------
    x : numpy array
        Position vector
        Expected shape: [num_time_step, 3, num_element]
    r : numpy array
        Radius vector
        Expected shape: [num_time_step, num_element]
    color : str
        Color of the rod (default: Purple <0.45,0.39,1>)
    transmit : float
        Transparency (0.0 to 1.0).
    interpolation : str
        Interpolation method for sphere_sweep
        Supporting type: 'linear_spline', 'b_spline', 'cubic_spline'
        (default: linear_spline)
    deform : str
        Additional object deformation
        Example: "scale<4,4,4> rotate<0,90,90> translate<2,0,4>"

    Returns
    -------
    cmd : string
        Povray script
    """

    assert interpolation in ["linear_spline", "b_spline", "cubic_spline"]
    tab = "    "

    # Parameters
    num_element = r.shape[0]

    lines = []
    lines.append("sphere_sweep {")
    lines.append(tab + f"{interpolation} {num_element}")
    for i in range(num_element):
        lines.append(tab + f",<{x[0,i]},{x[1,i]},{x[2,i]}>,{r[i]}")
    lines.append(tab + "texture{")
    lines.append(tab + tab + "pigment{ color %s transmit %f }" % (color, transmit))
    lines.append(tab + tab + "finish{ phong 1 }")
    lines.append(tab + "}")
    if deform is not None:
        lines.append(tab + deform)
    lines.append(tab + "}\n")

    cmd = "\n".join(lines)
    return cmd