Menu

Determining the outline of a guide/path?

Help
engelhro
2015-10-28
2015-10-30
  • engelhro

    engelhro - 2015-10-28

    Hello,

    My aim is to get the outline of a guide/path (2D) which I draw with let's say a very thick pen. For reasons of simplicity I use a solid pen, not a dashed one or similar, so the result is one single shape (I want to use different linecaps and linejoins though, possibly even various shapes for the pen itself).

    Having no idea how to achieve that, I finally stumbled upon the "strokepath" command in the manual which seemed to fit. I've come up with the following simple example:

    unitsize(1cm);
    pen p = linewidth(1cm);
    guide g = (0,0){0} .. {0}(5,5);
    draw(g, p+blue);
    draw(g, red);
    add(new void(frame f, transform t) {
        draw(f,strokepath(t*g,p));
      });
    //currentpicture.addPath(g,p);
    

    I have some questions here:

    1. Is "strokepath" the right approach at all? I'm not sure. If no: what would be the easiest way to determine the contour of a guide/path drawn with a certain pen and have it available as another guide/path in the end?
      If the answer is yes, then I have more questions with regard to my example (base path in red, the shape I'd like to have as a guide in blue, and the strokepath result in black). It is based on this old thread I found:
      Strokepath limitation?
    2. How does this "add" work? I understand from the manual that this approach is necessary to cope with the difference between Postscript coordinates and the ones in my drawing, e.g., to scale the result accordingly. But I did not find "add" with a single argument which is a function returning void… What exactly is going on here?
    3. Inside that anonymous function, a "draw" command is used which uses as first parameter a frame. Again, "draw" with such a signature is not documented in the manual…
    4. The last line of my example (commented out) was taken over from the old example I referenced. Why is that additional step necessary, what's the purpose of that line? And where does "addPath" to a picture come from, it's (once more) not contained in the manual?
      As you see, I'm quite confused - I see that this stuff somehow works but I'd like to better understand why.
      And there's more:
    5. Why does the black path (the "strokepath" result) not fully cover the blue shape? Obviously "strokepath" does not consider the linecap (round one in this case)?
    6. If "strokepath" returns an array of points (pairs), how do I convert that to an as simple as possible guide/path again? Or am I completely on the wrong track?

    Thanks for some helpful hints!

     
  • Charles Staats

    Charles Staats - 2015-10-30

    strokepath appears to return an array of rectangles and triangles that, if filled, will produce a close approximation of the path in question. These rectangles and triangles are allowed to overlap each other.

    In short, I don't think it is appropriate for what you're trying to do.

     

Log in to post a comment.