Skip to content

Instantly share code, notes, and snippets.

@chaoxu
Created December 15, 2014 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaoxu/742d0f309a124636b09f to your computer and use it in GitHub Desktop.
Save chaoxu/742d0f309a124636b09f to your computer and use it in GitHub Desktop.
buildSegment[a_, xs_, x_] :=
If[Length[xs] == 1, {},
Join[{ { xs[[1]] + (x - a)*Sign[xs[[2]] - xs[[1]]],
a <= x <= a + Abs[xs[[1]] - xs[[2]]]} },
buildSegment[ a + Abs[xs[[1]] - xs[[2]]], Rest[xs], x]] ]
Curve[xs_, x_] := Piecewise[buildSegment[0, xs, x]]
MaxLength[xs_] :=
Sum[ Abs[xs[[i]] - xs[[i + 1]]], {i, 1, Length[xs] - 1}]
FreeDiagram[xs_, ys_, epsilon_] :=
RegionPlot[
Abs[Curve[xs, x] - Curve[ys, y]] <= epsilon, {x, 0,
MaxLength[xs]}, {y, 0, MaxLength[ys]} , AspectRatio -> Automatic,
PerformanceGoal -> "Quality", PlotPoints -> 100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment