1

Say I have a type Path a = Double -> a. That describes some notion of a "path" in a given type a. In my case I want to use this to draw a curve in a 2-dimensional space. I use diagrams so let a = P2 Double (P2).

What I'm looking for is a (generic) way of sampling any path p :: Path (P2 Double) so that I can generate a smooth curve. Currently I just generate a fixed set of Doubles that I sample p along. However, this only works nicely if p is relatively smooth w.r.t. the sample rate.

fredefox
  • 681
  • 3
  • 11
  • Ok, you're looking for a way to do this. What research have you done? What attempts have you made? We're not just going to write this (quite nontrivial) code for you. – AJF Oct 17 '18 at 13:57
  • I don't know how to remove the question again. If you feel this is off-topic go right ahead, sir. – fredefox Oct 17 '18 at 13:59

1 Answers1

2

Can't be done. If you want a "good" sample of a function, you must assume something about smoothness of the function; without any assumptions functions can be wildly weird. For example, the Weierstrass function is continuous everywhere and differentiable nowhere; the rationality indicator is bounded but discontinuous everywhere; and indeed by any sane metric the vast majority of functions are not even computable let alone easily interrogatable for a set of "representative" inputs.

So make some assumptions, or demand that the user tell you how to sample.

Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380
  • 1
    Although this is true, it's not really an answer, is it? In fact one might interpret that the question is actually about _what assumptions are reasonable_ to make about a function that should be drawn as a path. Yeah, in a cardinality sense most ℝ→ℝ functions are utterly discontinous, but most functions _you'd actually want to plot_ are probably infinitely differentiable almost everywhere... – leftaroundabout Oct 17 '18 at 14:42
  • 1
    @leftaroundabout Sure, and I'd upvote an answer about what assumptions are reasonable, if you have some in mind. Especially if the conclusion of those assumptions is something different than "generate a fixed set of `Double`s to sample along", the existing proposed solution. I would find that outcome surprising and probably enlightening. – Daniel Wagner Oct 17 '18 at 14:46
  • 1
    I will write an answer later today. – leftaroundabout Oct 17 '18 at 14:52
  • If you assume that you also can compute the curvature of the function at any given point, I could imagine some kind of adaptive sampling process where you start with some fixed set of points and then "zoom in" on places where the function seems to be changing more quickly. @leftroundabout , I'd be interested to read your promised answer! – Brent Yorgey Oct 22 '18 at 16:50