I'm wondering if anyone has a nice solution for breaking a kinked line into $(n-1)$ segments of equal euclidean distance?
Here is a MWE of my attempt. I think it does the job, and I'm sure the code can be improved, but I'm wondering if there is an much more simple/elegant way to do the job
topslope = .5;
botslope = 2;
kinkptX = 7.5;
kinkptY = 15;
kLine[x_]:=Piecewise[{{(kinkptY+kinkptX topslope)-topslope x,x<=kinkptX},{(kinkptY+kinkptX botslope)-botslope x,x>kinkptX}}]
(*Get Euclidean length of line *)
dist = Module[{xint},
xint = Solve[kLine[x] == 0, x][[1, 1, 2]];
EuclideanDistance[{xint, 0}, {kinkptX, kLine[kinkptX]}] +
EuclideanDistance[{kinkptX, kLine[kinkptX]}, {0, kLine[0]}]
];
(*note: n is number of points, which will give (n-1) segments *)
makePieces[n_] :=
Module[{dist1, pLen, a, lowdist, ptForRdist, rKpt, rLpt, ptForLdist,
highdist, xint},
dist1 = dist/(n - 1) ;
xint = Solve[kLine[x] == 0, x][[1, 1,
2]];(*divide by n-1 to get n-1 equal length segments,
consisting of n points *)
ptForRdist =
Solve[EuclideanDistance[{xint, 0}, {x, kLine[x]}] == dist1 &&
kinkptX <= x < xint, x][[1, 1,
2]]; (*this point is used to find the distance between points on \
portion of the line to the right of the kink *)
ptForLdist =
Solve[EuclideanDistance[{0, kLine[0]}, {x, kLine[x]}] == dist1 &&
0 < x < kinkptX, x][[1, 1,
2]];(*this point is used to find the distance between points on \
portion of the line to the left of the kink *)
highdist = ptForLdist - 0; (*
this gives distance between points on upper portion *)
lowdist =
xint - ptForRdist; (*this gives distance between points on lower \
portion *)
a = {};
For[i = kinkptX; t = 0, i <= xint, i = i + lowdist,
AppendTo[a, xint - t]; t = t + lowdist];
rKpt = Last[a];(*point to the right of the kink *)
rLpt = Solve[
EuclideanDistance[{rKpt, kLine[rKpt]}, {kinkptX,
kLine[kinkptX]}] +
EuclideanDistance[{kinkptX, kLine[kinkptX]}, {x, kLine[x]}] ==
dist1 && 0 <= x < kinkptX, x][[1, 1, 2]];
For[i = rLpt, i >= 0, i = i - highdist, AppendTo[a, i]];
a
]
makePieces[4]
(note: the above needs to be modified to better deal with if solve encounters no solutions, since you can't take parts of {}



