I'm trying to create a dynamic piecewise function. I can get 3 points, but after that, everything gets a bit complicated:
Manipulate[DynamicModule[{pts = {{0, 0}, {1, 1}, {2, 2}}},
LocatorPane[Dynamic[pts],
Dynamic[Column[{Plot[
Piecewise[{
{x (y2 - y1)/( pts[[2, 1]] - pts[[1, 1]]),
pts[[1, 1]] <= x < pts[[2, 1]]},
{x (y3 - y2)/(pts[[3, 1]] - pts[[2, 1]]) + (y2 - y1)/(
pts[[2, 1]] - pts[[1, 1]]) - (y3 - y2)/(pts[[3, 1]] -
pts[[2, 1]]), pts[[2, 1]] <= x < pts[[3, 1]]}
}],
{x, 0, 2}, PlotRange -> {{0, 2}, {0, 2}}, ImageSize -> Large],
Piecewise[{{x (y2 - y1)/(pts[[2, 1]] - pts[[1, 1]]), pts[[1, 1]] <= x <
pts[[2, 1]]}, {x (y3 - y2)/(pts[[3, 1]] - pts[[2, 1]])
+ (y2 - y1)/(pts[[2, 1]] - pts[[1, 1]]) - (y3 - y2)/(pts[[3, 1]]
- pts[[2, 1]]), pts[[2, 1]] <= x < pts[[3, 1]]}}]}]],
Appearance -> None]],
{y1, 0, 2}, {{y2, 1}, 0, 2, Appearance -> None}, {{y3, 2}, 0, 2}]
Is there a nice way to do this?


