Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Parametric plot with piecewise input

I'm trying to plot a parametric function, which is defined piecewise. For some reason, the plot just jumps to the last piece of the parametric function and plots that.

Here's what I want to plot.

t = var('t')
r = 2

def f(x):
    if 0 <=x <=r:
        return (x, -r)
    elif r<x<=r + pi*r:
        return (cos(x-r), -(r + sin(x-r)))
    elif r + pi*r < x <= 3*r + pi*r:
        return (-x + 2*r + pi*r, r)
    elif 3*r + pi*r < x <= 3*r + 2*pi*r:
        return (cos(x - 3*r), -(r + sin(x-r)))
    else:
        return (x - 4*r - 2*pi*r, -r)

    parametric_plot(f(t), (t, 0, 4*r + 2*pi*r))

It just returns a straight line of length 4r + 2pi*r with y coordinate -r